strelov1
8/31/2016 - 6:02 AM

count case

SELECT
  created_at,
  call_manager_id,
  count(CASE
        WHEN (call_center_stat.status_call = 1 AND call_center_stat.status = 1)
          THEN 1
        ELSE NULL
        END) AS status_success,
  count(CASE
        WHEN call_center_stat.status_call = 2
          THEN 1
        ELSE NULL
        END) AS status_decline,
  count(CASE
        WHEN call_center_stat.status_call = 3
          THEN 1
        ELSE NULL
        END) AS status_not_reponse,
  count(CASE
        WHEN call_center_stat.status_call = 4
          THEN 1
        ELSE NULL
        END) AS status_call_try_later,
  count(CASE
        WHEN call_center_stat.status = 3
          THEN 1
        ELSE NULL
        END) AS status_already_registered
FROM `call_center_stat`
WHERE (`created_at` > '2016-08-17 00:00:00')
AND (`created_at` < '2016-08-22 24:00:00')
GROUP BY call_manager_id, DATE_FORMAT(created_at, '%m%d');