I need help creating a query . I want to group by Period and Jobid. For each grouping I need to sum the hourworkedtotal for each period. This value will also include any periods prior to this period.
For example MAR20 and Jobid 3391 would have an hoursworkedtotal of 93 as Feb20 hoursworkedtotal will be included.
Advertisement
Answer
You can use window functions with aggregation:
select period, jobid, sum(hoursworkedtotal) as this_month, sum(sum(hoursworkedtotal)) over (partition by jobid order by period) as running_hours from t group by period, jobid;