Reputation: 1313
I have a mysql table as in below figure.
I want to query to this table so that I get data as follows:
I am using the following query.
SELECT SUM(TOTAL_HOURS) AS TOTAL_HOURS, CLIENT_ID, `DAY`
FROM timesheet_slave
GROUP BY CHARGE_ID, `DAY`;
And getting result as below:
How do I merge similar row with client id and get data as in following table?
Any help would be appreciated. Thanks
Upvotes: 0
Views: 69
Reputation: 72185
You can use conditional aggregation for this as shown below:
SELECT CLIENT_ID,
SUM(IF(`DAY`='Working', TOTAL_HOURS, 0)) AS TOTAL_WORKING_HOURS,
SUM(IF(`DAY`='Holiday', TOTAL_HOURS, 0)) AS TOTAL_HOLIDAY_HOURS
FROM timesheet_slave
GROUP BY CLIENT_ID ;
Upvotes: 1