MYSQL查询之多表查询select嵌套的三种形式。 | 您所在的位置:网站首页 › sql嵌套查询和多表联合查询之间的差别是什么 › MYSQL查询之多表查询select嵌套的三种形式。 |
一、(having,group by,select嵌套放在select里)
可参考 https://www.jianshu.com/p/8b135d373df1 二、(not in,distinct去重,select嵌套放在where里)表的内容如下: 实现功能:查询没学过"张三"老师授课的同学的信息 实现语句: SELECT student.s_id,student.s_name FROM student WHERE s_id not in (SELECT distinct( score.s_id) FROM score,course,teacher WHERE score.c_id=course. c_id AND course.t_id=teacher.t_id AND teacher.t_name='张三'); 三,(select嵌套放在from里)表可参照2实现功能:查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息 实现语句: SELECT *from (SELECT s_id,s_score from score WHERE score.c_id ="01")as t1,(SELECT s_id,s_score from score WHERE score.c_id="02") as t2 WHERE t1.s_id=t2.s_id
|
CopyRight 2018-2019 实验室设备网 版权所有 |