按年按月分组查询
這里以 Oracle 為例子。
to_char 方法
select to_char(tj_date, 'YYYY-MM'), count(*) tj, count(case when o3>160 then 1 else null end) o3_160, count(case when o3>160 then 1 else null end)/count(*) from O3 group by to_char(tj_date, 'YYYY-MM') order by 1;單獨抽取每月的數(shù)據(jù)
select to_char(tj_date, 'MM'), count(*), count(case when o3>160 then 1 else null end) o3_160 from O3 group by to_char(tj_date, 'MM') order by 1;Extract 方法
以下例子,抽取月
select EXTRACT(month from DATE_CREATED), sum(Num_of_Pictures) from pictures_table group by EXTRACT(month from DATE_CREATED);Ref
Oracle Extract Datetime
How to query group by month in a year
轉(zhuǎn)載于:https://www.cnblogs.com/flowerszhong/p/7001314.html
總結(jié)
- 上一篇: 前端学习笔记2017.6.12 CSS控
- 下一篇: 关于如何准备一份制胜简历的清单