当前位置:   article > 正文

mysql中select嵌套select_MYSQL查询之多表查询select嵌套的三种形式。

select嵌套select

一、(having,group by,select嵌套放在select里)

可参考 https://www.jianshu.com/p/8b135d373df1

二、(not in,distinct去重,select嵌套放在where里)

表的内容如下:

722c625967eb11560f67140e1307d879.png

33c4eed8d8bf44f8caaa6ea057109903.png

a72959287b77c071740c88b2ed8cd89f.png

542da3796c359e424943491bf217a81a.png

实现功能:查询没学过"张三"老师授课的同学的信息

实现语句:

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/665951
推荐阅读
相关标签
  

闽ICP备14008679号