MySQL Forums
Forum List  »  General

Like a cross tab query.
Posted by: tijenderpopli
Date: August 16, 2006 02:49AM

There is one table Payroll
having field names
Date employid Paidamount
I want to get sum of Paidamount on different dates (from given date to six days back) in a table like Dates as column name and sum of paid amont at that date as data.
the query i have used is

select
sum(CASE when Date=DATE_ADD('yyyy-mm-dd',INTERVAL -6 DAY) then Paidamount else 0 end) as FisrtDay,
sum(CASE when Date=DATE_ADD('yyyy-mm-dd',INTERVAL -5 DAY) then Paidamount else 0 end) as SecondDay,
sum(CASE when Date=DATE_ADD('yyyy-mm-dd',INTERVAL -4 DAY) then Paidamount else 0 end) as ThirdDay,
sum(CASE when Date=DATE_ADD('yyyy-mm-dd',INTERVAL -3 DAY) then Paidamount else 0 end) as FourthDay,
sum(CASE when Date=DATE_ADD('yyyy-mm-dd',INTERVAL -2 DAY) then Paidamount else 0 end)as FifthDay,
sum(CASE when Date='yyyy-mm-dd' then Paidamount else 0 end) as sixthDay
from Payroll

(Here 'yyyy-mm-dd' represents the given date.)
But i want to get the value of Date field itself as the column name(there should be date in place of FirstDay,SecondDay,ThirdDay,FourthDay,FifthDay.



Edited 5 time(s). Last edit at 08/16/2006 04:04AM by tijenderpopli.

Options: ReplyQuote


Subject
Written By
Posted
Like a cross tab query.
August 16, 2006 02:49AM
August 16, 2006 05:44PM
August 16, 2006 10:45PM
August 17, 2006 09:20AM
August 17, 2006 11:35PM
August 18, 2006 01:53AM
August 18, 2006 02:16AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.