oracle统计

来源:互联网 发布:南财网络教育平台 编辑:程序博客网 时间:2024/05/29 12:16
  1. -----按天统计  
  2. select to_char(t.hiredate, 'yyyy/mm/dd') 日期, count(1) 数量  
  3.     from EMP t  
  4.  where t.hiredate >= to_date('1980/1/1''yyyy/mm/dd')  
  5.      and t.hiredate <= to_date('2017/1/31''yyyy/mm/dd')  
  6.  group by to_char(t.hiredate, 'yyyy/mm/dd')  
  7.  order by 日期;  
  8.   
  9. ---按月统计  
  10. select to_char(t.hiredate, 'yyyy/mm') 日期, count(1) 数量  
  11.     from EMP t  
  12.  where t.hiredate >= to_date('1980/1/1''yyyy/mm/dd')  
  13.      and t.hiredate <= to_date('2017/12/31''yyyy/mm/dd')  
  14.  group by to_char(t.hiredate, 'yyyy/mm')  
  15.  order by 日期;  
  16.   
  17. -----按年统计  
  18. select to_char(t.hiredate, 'yyyy') 日期, count(1) 数量  
  19.     from EMP t  
  20.  where t.hiredate >= to_date('1980/1/1''yyyy/mm/dd')  
  21.      and t.hiredate <= to_date('2017/12/31''yyyy/mm/dd')  
  22.  group by to_char(t.hiredate, 'yyyy')  
  23.  order by 日期;  
  24.    
  25.  -----按季度统计  
  26. select to_char(t.hiredate, 'q') 日期, count(1) 数量  
  27.     from EMP t  
  28.  where t.hiredate >= to_date('1980/1/1''yyyy/mm/dd')  
  29.      and t.hiredate <= to_date('2017/12/31''yyyy/mm/dd')  
  30.  group by to_char(t.hiredate, 'q')  
  31.  order by 日期;  
  32.    
  33.   -----按周统计  
  34. select to_char(t.hiredate, 'iw') 日期, count(1) 数量  
  35.     from EMP t  
  36.  where t.hiredate >= to_date('1980/1/1''yyyy/mm/dd')  
  37.      and t.hiredate <= to_date('2017/12/31''yyyy/mm/dd')  
  38.  group by to_char(t.hiredate, 'iw')  
  39.  order by 日期;