单表查询总结

select语句总结:

 

select column,group_function(column)
from table
(where condition)
(group by group_by_expression)
(having group_condition)
(order by column);

注意:顺序固定,不可以改变顺序

 

select语句的执行循序:

from-->where-->group by-->select-->having-->order by 

 

单表查询练习:

1.列出工资最小值小于2000的职位

 

select job,min(sal)
from emp
group by job
having min(sal) < 2000;

运行结果:

 

 2.列出平均工资大于1200元的部门和工作搭配组合

 

select deptno,job,avg(sal)
from emp
group by deptno,job
having avg(sal) > 1200
order by deptno ;

运行结果:

 

 3.统计(人数小于4的)部门的平均工资

 

select deptno,count(1),avg(sal)
from emp
group by deptno
having count(1) < 4;

运行结果:

 

 4.统计各部门的最高工资,排除最高工资小于3000的部门

 

select deptno,max(sal)
from emp
group by deptno
having max(sal) <3000;

运行结果:

 

posted @ 2022-01-02 00:38  努力学爪哇  阅读(50)  评论(0编辑  收藏  举报