数据库
首页 > 数据库> > MySQL高级之子查询

MySQL高级之子查询

作者:互联网

查询支持嵌套使用

查询各学生的语文、数学、英语的成绩

select sname,
(select sco.score from scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle='语文' and stuid=stu.id) as 语文,
(select sco.score from  scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle='数学' and stuid=stu.id) as 数学,
(select sco.score from  scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle='英语' and stuid=stu.id) as 英语
from students stu;

 

标签:sco,sub,查询,stu,之子,MySQL,stuid,id,select
来源: https://www.cnblogs.com/mxsf/p/10889226.html