Mysql必练50题(第二天)

第六题
查询"李"姓老师的数量

select t_name,count(*) from teacher where t_name like "李%";

在这里插入图片描述
第七题
查询学过"张三"老师授课的同学的信息

select s.* from student s 
inner join score sc on s.s_id = sc.s_id 
inner join course c on sc.c_id = c.c_id
inner join teacher t on c.t_id = t.t_id
where t_name = "张三";

在这里插入图片描述
第八题
查询没学过"张三"老师授课的同学的信息

select * from student where s_id not in
(select sc.s_id from score sc inner join course c on sc.c_id = c.c_id
inner join teacher t on c.t_id = t.t_id where t_name = "张三"
);

在这里插入图片描述
第九题
查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息

select * from student where s_id in (select sc1.s_id from 
(select * from score sc where c_id = 1) sc1
inner join 
(select * from score sc where c_id =2) sc2
on sc1.s_id = sc2.s_id)

在这里插入图片描述
第十题
查询学过编号为"01"但是没有学过编号为"02"的课程的同学的信息

select * from student where s_id in 
(select s_id from score where c_id = 1 and s_id not in 
(select s_id from score where c_id = 2));

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值