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

Database

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

6 REPLIES
Enthusiast

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

Can you provide columns details or DDL?

Tags (1)
Teradata Employee

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

It's probably either

    select sum(sal) group by quarter

or

    select sum(sal) group by (case when paydate between date'01-01-16' and date'03-31-16' then 1

                            when paydate between date'01-01-16' and date'03-31-16' then 1

 

Teradata Employee

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

It's probably something like either
    select sum(sal) group by quarter
or
    select sum(sal) group by (case when paydate between date'01-01-16' and date'03-31-16' then 1
                    when paydate between date'04-01-16' and date'06-30-16' then 2
                    when paydate between date'07-01-16' and date'09-30-16' then 3
                    else 4 end) as quarter

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

If i want result for 3years of data then how can i write? 

Teradata Employee

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

Join to Sys_Calendar.Calendar, viz.:

select sum(P.sal)
      ,C.Quarter_Of_Year
      ,C.Year_Of_Calendar
from   <payments> P
      ,sys_calendar.calendar C
 where P.PayDate = C.Calendar_Date    
 and   P.PayDate between <define your timeframe>
group by C.Year_Of_Calendar, C.Quarter_Of_Year
order by C.Year_Of_Calendar, C.Quarter_Of_Year

Junior Contributor

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

Or use TRUNC(PayDate, 'Q') which returns the first day of the quarter.