1. GROUP BY
GROUP BY必须得配合聚合函数来用,分组之后你可以计数(COUNT),求和(SUM),求平均数(AVG)等。
select
dept_no as 部门, (字段要么包含在Group By的后面,要么包含在聚合函数中)
count(amp_no) as 人数
from
dot_emp
where
to_date='9999-01-01'
group by
dept_no
2. HAVING
where:在分组group by前,过滤数据,不能包含聚合函数
having:在分组group by后,过滤数据,经常包含聚合函数
select
......
from
......
where
......
group by
......
having
......
3. ORDER BY
select
......
from
......
group by
......
order by
sum(......) DESC
LIMIT 1
网友评论