关于练习中查询1 的问题
相关代码:
select DISTINCT s1.Sname from student s1 join
(select DISTINCT s.Sname from student s join sc c on s.S = c.S join
Course cou
on c.C = cou.C join teacher t on cou.t = t.T
where t.Tname ="张三"
GROUP BY s.Sname) ss on s1.Sname not in (ss.Sname)
相关截图:
问题描述:
并不能查询出想要的结果,请问老师为什么这样写不行呢,最简单快捷的方法是什么呢
48
收起
正在回答 回答被采纳积分+1
1回答
好帮手慕小小
2021-10-08 13:14:30
同学你好,可以尝试使用如下sql语句实现查询没学过"张三"老师授课的同学的信息:
SELECT * FROM student WHERE student.S NOT IN( SELECT S FROM (SELECT stu.S,stu.Sname,sc.C FROM student stu LEFT JOIN sc ON stu.S = sc.S) temp LEFT JOIN course c ON temp.C = c.C LEFT JOIN teacher t ON t.T = c.T WHERE t.Tname="张三")
查询学过张三课程的学生信息:
SELECT temp.S,temp.Sname,c.Cname,t.Tname FROM (SELECT stu.S,stu.Sname,sc.C FROM student stu LEFT JOIN sc ON stu.S = sc.S) temp LEFT JOIN course c ON temp.C = c.C LEFT JOIN teacher t ON t.T = c.T WHERE t.Tname="张三"
祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星