postgresql-聚合函数增强功能
- 按季度统计入职员工
按季度统计入职员工
select
-- extract截取,按季度进行统计入职员工总数
extract(year from hire_date),
count(*) filter(where extract(quarter from hire_date) = 1) "第一季度",
count(*) filter(where extract(quarter from hire_date) = 2) "第二季度",
count(*) filter(where extract(quarter from hire_date) = 3) "第三季度",
count(*) filter(where extract(quarter from hire_date) = 4) "第四季度"
from employees e
-- 1表示按查询结果第一列进行分组
group by 1;