常用SQL(二)

--排序
select * from emp order by job;

--分组
select job,max(sal) from emp group by job;

--having
select job,max(sal) from emp group by job having max(sal)>=2000;
--按年龄段列举出班上最高分数超过80的年龄段
select age,max(score) from student group by age having max(score)>80;

--列举班上最大的男生,(用到子查询)
select name from student where age in (select max(age) from student where sex=1) and sex=1;

--查询出 所有工种中 平均工资 最高的
select job,avg(sal) from emp group by job having avg(sal)=
(
   select max(avg_sal) from
      (select job,avg(sal) avg_sal from emp group by job)
);

全部评论

相关推荐

想去夏威夷的小哥哥在度假:5和6才是重点
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务