how to get sum(sal) for every quarter in yearwise

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.

how to get sum(sal) for every quarter in yearwise

Hi,can any one give me the query for sum of salries for every quarter in year wise

  • Database
1 REPLY
Enthusiast

Re: how to get sum(sal) for every quarter in yearwise

Dear Samba Siva,

 

Join your reporting date to the sys_calendar.calendar view and you can pull "quarter_of_year" from the system calendar. In case you need to change the QOY field to represent a fiscal or other operating interpretation, just build a semantic calendar view on top of the system calendar.

 

Sample code as below will help:

select	est.emp_id, cal.quarter_of_year, sum(est.emp_sal)
from	emp_salary_table est
inner join sys_calendar.calendar cal
	on	est.emp_salary_dt = cal.calendar_date
where	cal.calendar_date between '2016-01-01' and '2016-12-31'
	and	est.emp_id = '123'
	group by 1,2;

 Output:

 

Emp_Idquarter_of_yearSum(emp_sal)
1231985,657.32
1232668,119.65
1233761,205.19
1234809,106.21

 

Hope this helps!