Oracle按天、按月統計資料
阿新 • • 發佈:2019-02-13
-----按天統計 select to_char(t.hiredate, 'yyyy/mm/dd') 日期, count(1) 數量 from EMP t where t.hiredate >= to_date('1980/1/1', 'yyyy/mm/dd') and t.hiredate <= to_date('2017/1/31', 'yyyy/mm/dd') group by to_char(t.hiredate, 'yyyy/mm/dd') order by 日期; ---按月統計 select to_char(t.hiredate, 'yyyy/mm') 日期, count(1) 數量 from EMP t where t.hiredate >= to_date('1980/1/1', 'yyyy/mm/dd') and t.hiredate <= to_date('2017/12/31', 'yyyy/mm/dd') group by to_char(t.hiredate, 'yyyy/mm') order by 日期; -----按年統計 select to_char(t.hiredate, 'yyyy') 日期, count(1) 數量 from EMP t where t.hiredate >= to_date('1980/1/1', 'yyyy/mm/dd') and t.hiredate <= to_date('2017/12/31', 'yyyy/mm/dd') group by to_char(t.hiredate, 'yyyy') order by 日期; -----按季度統計 select to_char(t.hiredate, 'q') 日期, count(1) 數量 from EMP t where t.hiredate >= to_date('1980/1/1', 'yyyy/mm/dd') and t.hiredate <= to_date('2017/12/31', 'yyyy/mm/dd') group by to_char(t.hiredate, 'q') order by 日期; -----按周統計 select to_char(t.hiredate, 'iw') 日期, count(1) 數量 from EMP t where t.hiredate >= to_date('1980/1/1', 'yyyy/mm/dd') and t.hiredate <= to_date('2017/12/31', 'yyyy/mm/dd') group by to_char(t.hiredate, 'iw') order by 日期;