Tag Info

New answers tagged

0

you can also do this by using case statement. Select DATE_FORMAT(date,'%m-%d %H:00') AS Date, sum(case when type = 'staff' then 1 else 0 end) as 'Staff Count', sum(case when type = 'client' then 1 else 0 end) as 'Client Count' from ticket_data where type='staff' or type='client' and department='support' group by DAY(Date), HOUR(Date) ORDER BY `Date` ASC ...


0

This is a common trick of counting conditionally into several columns, depending on a condition using the IF() expression: mysql> SELECT DATE_FORMAT(date,'%m-%d %H:00') AS Date, SUM(IF(type = 'client', 1, 0)) AS `Client Count`, SUM(IF(type = 'staff', 1, 0)) AS `Staff Count`, FROM ticket_data WHERE department = 'support' ...



Top 50 recent answers are included