MySQL单表查询作业和多表查询作业截图

本文通过实际案例,展示了如何使用MySQL进行单表及多表查询操作,涵盖了基于给定图表的数据提取技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是题干
根据上图的表用MySQL查询出以下题

1:查询所有学生的信息
select * from students

2:查询姓名是李白的学生信息
select * from students where name='李白'

3:查询1班是上海的学生
select * from students where class='1班' and hometown='上海'

4:查询家乡是北京或者上海的学生
select * from students where hometown='北京' or hometown='上海'


5:查询小乔的年龄
select name,age as '年龄' from students where name='小乔'


6:查询家乡不在北京的学生
select * from students where hometown!='北京'

7:查询年龄小于20的女同学
select * from students where age<20 and sex='女'

8:查询年龄为1820的学生
select * from students where age<=20 and age>=18

9:查询北京学生的年龄总和
select sum(age) from students where hometown='北京'

10:查询女生的平均年龄
select avg(age) from students where sex='女'

11:查询姓名包含白的学生
select * from students where name like '%白%'

12:查询所有学生信息,俺年龄从大到小排序,年龄相同时,再按学号从小到大排序
select * from students order by age desc,studentNo asc


13:查询女生的最大年龄
select max(age) from students where sex='女'

14:查询北京学生的年龄总和
select sum(age) from students where hometown='北京'

15:查询各种性别的人数
select count(*),sex from students group by sex

16:查询男生总人数

select count(*),sex from students where sex='男'

在这里插入图片描述根据上图三个表用MySQL进行查询以下三个题

1.查询sc表中对应何昊老师所教授课程的女生的信息

select x.sname from xueshengxinxibiao as x inner join teacher as t inner join sc on x.sno=sc.sno and t.Cno = sc.cno where x.sex='女' and t.Cteacher='何昊'

2.找出没有选修何老师的课程的所有学生的姓名

SELECT xueshengxinxibiao.sname FROM xueshengxinxibiao WHERE sno not in (SELECT sc.sno FROM sc INNER JOIN teacher ON sc.cno = teacher.cno AND teacher.Cteacher = '何昊');

3.列出有不及格课程(成绩小于60)的学生的姓名

select distinct(x.sname) from xueshengxinxibiao as x inner join teacher as t inner join sc on x.sno=sc.sno and t.Cno = sc.cno where sc.scgrade < 60
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值