I have a table like this:
----------------------------------- | Name | Date | Campaign | ----------------------------------- | John | July | Email | | Carl | August | Phone | | John | July | Phone | | Robert | August | Phone | | Carl | September | Email | | John | August | Phone | | Carl | August | Email | | John | July | Email | | Robert | September | Phone | | Carl | August | Email | -----------------------------------
I count the data grouped by date and campaign, but I would like an additional column to bring me the total number of lines that have that campaign
the query I use:
SELECT campaign,name,
SUM(IF(date = 'July',1,0)) AS July,
SUM(IF(date = 'August',1,0)) AS August,
SUM(IF(date = 'September',1,0)) AS September
FROM table
GROUP BY name,campaign
but I would like to modify it to get the following output:
---------------------------------------------------------------------------------------- | Campaign | Name | July | August | September | SUM July | SUM August | SUM September | ---------------------------------------------------------------------------------------- Email John 2 0 0 2 2 1 Phone John 1 1 0 1 3 1 .... ....
I would like the columns with the total of all the values with phone or email distinguished by month