当前位置: 首页 > news >正文

数据库第三次作业

请添加图片描述
创建数据库mydb11_stu并进入数据库:
create database mydb11_stu; use mydb11_stu;
创建student表
create table student(id int(10) not NULL unique primary key, name varchar(20) not NULL, sex varchar(4), birth year, department varchar(20), address varchar(50));
创建score表:
create table score(id int(10) not NULL unique primary key auto_increment,stu_id int(10) not NULL,c_name varchar(20),grade int(10));
插入数据:
向score表插入:
insert into score values(null,901,'计算机',98); insert into score values(null,901,'英语',80); insert into score values(null,902,'计算机',65); insert into score values(null,902,'中文',88); insert into score values(null,903,'中文',95); insert into score values(null,904,'计算机',70); insert into score values(null,904,'英语',92); insert into score values(null,905,'英语',94); insert into score values(null,906,'计算机',49); insert into score values(null,906,'英语',83);

向student 表插入:
insert into student values(901,'张三丰','男',2002,'计算机系','北京市海淀区'); insert into student values(902,'周全有','男',2000,'中文系','北京市昌平区'); insert into student values(903,'张思维','女',2003,'中文系','湖南省永州市'); insert into student values(904,'李广昌','男',1999,'英语系','辽宁省皋新市'); insert into student values(905,'王翰','男',2004,'英语系','福建省厦门市'); insert into student values(906,'王心凌','女',1998,'计算机系','湖南省衡阳市');

查询:
(1)
select * from student; select * from score;
(2)
select * from student order by id limit 1,4;
(3)
select * from student where department in ('计算机系','英语系');
(4)
select * from student where 2025-birth<22;
(5)
select department ,count(*) as 人数 from student group by department;
(6)
select c_name,max(grade) as 最高分 from score group by c_name;
(7)
select s.c_name,s.grade from score s join student st on s.stu_id=st.id where st.name='李广昌';
(8)
select st.*,s.c_name,s.grade from student st join score s on st.id=s.stu_id;
(9)
select st.name,sum(s.grade) as 总成绩 from student st join score s on st.id=s.stu_id group by st.id;
(10)
select c_name,avg(grade) as 平均成绩 from score group by c_name;
(11)
select st.* from student st join score s on st.id=s.stu_id where s.c_name='计算机' and s.grade<95;
(12)
select st.name,s.grade from student st join score s on st.id=s.stu_id where s.c_name='计算机' order by s.grade desc;
(13)
select id as 学号 from student union select stu_id from score;
(14)
select st.name,st.department,s.c_name,s.grade from student st join score s on st.id=s.stu_id where st.name like '张%' or st.name like '王%';
(15)
select st.name,2025-st.birth as 年龄,st.department,s.c_name,s.grade from student st join score s on st.id=s.stu_id where st.address like '%湖南省%';


文章转载自:
http://calcitonin.pzdurr.cn
http://apochromatic.pzdurr.cn
http://brake.pzdurr.cn
http://abernethy.pzdurr.cn
http://anodal.pzdurr.cn
http://annulus.pzdurr.cn
http://abed.pzdurr.cn
http://arachne.pzdurr.cn
http://bishopric.pzdurr.cn
http://aftershock.pzdurr.cn
http://burdensome.pzdurr.cn
http://acolyte.pzdurr.cn
http://anabasis.pzdurr.cn
http://ameboid.pzdurr.cn
http://calicoed.pzdurr.cn
http://assessee.pzdurr.cn
http://baed.pzdurr.cn
http://bassi.pzdurr.cn
http://any.pzdurr.cn
http://auralize.pzdurr.cn
http://basilect.pzdurr.cn
http://chemiloon.pzdurr.cn
http://antimilitarism.pzdurr.cn
http://chromize.pzdurr.cn
http://caudaite.pzdurr.cn
http://availability.pzdurr.cn
http://bitmap.pzdurr.cn
http://chalicosis.pzdurr.cn
http://cgmp.pzdurr.cn
http://amyl.pzdurr.cn
http://www.dtcms.com/a/281379.html

相关文章:

  • 脚手架新建Vue2/Vue3项目时,项目文件内容的区别
  • yolo-world环境配置
  • 【PCIe 总线及设备入门学习专栏 5.1.1 -- PCIe PERST# 信号的作用】
  • 关于实习的经验贴
  • eSearch识屏 · 搜索 v14.3.0
  • Redis集群搭建(主从、哨兵、读写分离)
  • netstat -tlnp | grep 5000
  • 3.创建表-demo
  • 进程的内存映像,只读区,可读写区,堆,共享库,栈详解
  • 23.将整数转换为罗马数字
  • 磁悬浮轴承的“眼睛”:位移测量核心技术深度解析
  • 【监控实战】Grafana自动登录如何实现
  • 关于tresos Studio(EB)的MCAL配置之FEE
  • dataLoader是不是一次性的
  • 文心一言4.5企业级部署实战:多模态能力与Docker容器化测评
  • 告别手动迁移:使用 PowerShell 一键导出 IIS 配置,让服务器迁移更轻松
  • LSA链路状态通告
  • QT——文件选择对话框 QFileDialog
  • Transformer是什么 - 李沐论文《Attention Is All You Need》精读
  • 内网穿透实例:在 NAT 环境下通过 FRP 配置 ThinLinc 远程桌面 实现外网登录
  • zynq串口的例子
  • 自己训练大模型?MiniMind 全流程解析 (一) 预训练
  • 如何科学做好企业软件许可优化?
  • Day03_C语言网络编程20250715
  • Datawhale AI 夏令营第一期(机器学习方向)Task2 笔记:用户新增预测挑战赛 —— 从业务理解到技术实现
  • 如何理解flex: 1 1 50%
  • 【Unity基础】Unity中元素的层级排序
  • WPF,Winform,HTML5网页,哪个UI开发速度最快?
  • 线程(一) linux
  • 前端医疗生命体征