ORACLE SQL Running TOTAL and daytotal using window function

前端 未结 2 961
萌比男神i
萌比男神i 2021-01-06 11:49

From the EMPLOYEE table, I want to group the amount of records(employees hired) AND also have the running TOTAL per day. The format of the input is like this:

row         


        
相关标签:
2条回答
  • 2021-01-06 12:20
    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

    0 讨论(0)
  • 2021-01-06 12:27
    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)
    
    0 讨论(0)
提交回复
热议问题