#查询score中最高分的学生学号
SELECT sno,cno from score ORDER BY degree DESC LIMIT 0,1;
#查询每一们课程的平均成绩
SELECT cno,avg(degree) from score GROUP BY cno;
#查询至少5门,并且是以3开头的
select avg(Degree) from score where Cno like '3%' and group by Cno having count(*)>=5
链接要小表驱动大表,
所以如果是inner join,无所谓
left join 把大表放在后边
right join把大表放在前面
select a.*, b.* from tablea a
left outer join tableb b
on a.id = b.id
select a.id aid,a.age,b.id bid,b.name from tablea a
left join tableb b
on a.id = b.id
Where b.id is null
select a.id aid,a.age,b.id bid,b.name from tablea a
left join tableb b
on a.id = b.id
union
select a.id aid,a.age,b.id bid,b.name from tablea a
right join tableb b
on a.id = b.id
select a.id aid,a.age,b.id bid,b.name from tablea a
left join tableb b
on a.id = b.id
where b.id is null
union
select a.id aid,a.age,b.id bid,b.name from tablea a
right join tableb b
on a.id = b.id
where a.id is null
网友评论