测试必会的sql查询

这篇博客展示了10个实用的SQL查询例子,涵盖了从查询特定课程成绩到找出与特定学生有相同课程记录的学生等多种场景。通过这些示例,读者可以深入了解如何在实际中运用SQL进行复杂的数据分析。
摘要由CSDN通过智能技术生成

1.Course表
2.Score表
3.Student表
4.Teacher表
sql:
1、查询课程编号为“02”的总成绩
select * from Score where c_id=02;

2.查询课程编号为“01”的课程比“02”的课程成绩高的所有学生的学号
select st.*,a.s_core,b.s_core
from Student st
inner join (select s_id,s_core from Score where c_id=‘01’) a
on st.s_id=a.s_id
inner join (select s_id,s_core from Score where c_id=‘02’) b
on a.s_id=b.s_id
where a.s_core>b.s_core;

3.查询没学过“张三”老师课的学生的学号、姓名
select st.s_id,st.s_name from Student st
where st.s_id not in
(select sc.s_id from Score sc inner join Course co
on sc.c_id=co.c_id
inner join Teacher te
on te.t_id=co.t_id
where te.t_name=‘张三’);

4.查询没有学全所有课的学生的学号、姓名
select st.s_id,st.s_name from Student st
inner join Score sc on st.s_id=sc.s_id
group by st.s_id having count(c_id)<(select count(distinct c_id)from Course);

5,

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值