标签:数据 个学生 姓名 sub cts inner div uid 结果
students表的id---scores表的stuid
subjects表的id---scores表的subid
select students.sname,subjects.stitle,scores.score from scores inner join students on scores.stuid=students.id inner join subjects on scores.subid=subjects.id;
表A inner join 表B:表A与表B匹配的行会出现在结果中
表A left join 表B:表A与表B匹配的行会出现在结果中,外加表A中独有的数据,未对应的数据使用null填充
表A right join 表B:表A与表B匹配的行会出现在结果中,外加表B中独有的数据,未对应的数据使用null填充
select students.sname,avg(scores.score) from scores inner join students on scores.stuid=students.id group by students.sname;
select students.sname,avg(scores.score) from scores inner join students on scores.stuid=students.id where students.gender=1 group by students.sname;
select subjects.stitle,avg(scores.score) from scores inner join subjects on scores.subid=subjects.id group by subjects.stitle;
select subjects.stitle,avg(scores.score),max(scores.score) from scores inner join subjects on scores.subid=subjects.id where subjects.isdelete=0 group by subjects.stitle;
标签:数据 个学生 姓名 sub cts inner div uid 结果
原文地址:https://www.cnblogs.com/wuzaipei/p/9819685.html