簡體   English   中英

ORACLE SQL使用窗口函數運行TOTAL和daytotal

[英]ORACLE SQL Running TOTAL and daytotal using window function

從EMPLOYEE表中,我想對記錄數量(雇用的員工)進行分組,並且每天都有運行的TOTAL。 輸入的格式如下:

rownum  Hired_date_time
1       1/10/2012 11:00
2       1/10/2012 13:00
3       20/11/2012 10:00
4       20/11/2012 15:00
5       20/11/2012 16:00
6       30/12/2012 1:00

所需的輸出:

Hired_date.......Hired_per_day.........TOTAL_number_of_employees
1/10/2012 ...................2 ........2
20/11/2012 ..................3 ........5
30/12/2012 ..................1 ....... 6

GROUPING PERDAY沒問題:

select  trunc(Hired_date_time) as "Hired_date" , 
        count(*) as "Hired_per_day"
from employee
group by trunc(Hired_date_time)
order by trunc(Hired_date_time);

問題 :如何使用窗口函數獲得總計(在最后一列中)

select trunc(hired), 
       count(*) hired_today,       
       sum(count(*)) over (order by trunc(hired)) as running_total
from emp
group by trunc(hired)

http://sqlfiddle.com/#!4/4bd36/9

select trunc(hire_date), 
       count(*) over (partition by trunc(hire_date)) as hired_per_day,
       count(*) over (order by hire_date) as total_number_of_employees
from employee
order by trunc(hire_date)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM