MINI Sh3ll
INSERT INTO daily_customer_billings(client_id, `date`, airtel_success, airtel_failed, airtel_success_cost, airtel_failed_cost, vodafone_success, vodafone_failed, vodafone_success_cost, vodafone_failed_cost, vodafone_idea_success, vodafone_idea_failed, vodafone_idea_success_cost, vodafone_idea_failed_cost, reliance_jio_success, reliance_jio_failed, reliance_jio_success_cost, reliance_jio_failed_cost, total_counts, total_costs)
SELECT u.id, DATE_FORMAT(rs.responseon, '%Y-%m-%d') resp_date,
sum(case when rs.operator = 'airtel' and rs.url_response_code = 200 then 1 ELSE 0 END) airtel_successful,
sum(case when rs.operator = 'airtel' AND rs.url_response_code <> 200 then 1 ELSE 0 END) airtel_unsuccessful,
sum(case when rs.operator = 'airtel' and rs.url_response_code = 200 then rs.msg_cost ELSE 0 END)/100 airtel_successful_cost,
sum(case when rs.operator = 'airtel' and rs.url_response_code <> 200 then rs.msg_cost ELSE 0 END)/100 airtel_successful_cost,
sum(case when rs.operator = 'vodafone' and rs.url_response_code = 200 then 1 ELSE 0 END) vodafone_successful,
sum(case when rs.operator = 'vodafone' AND rs.url_response_code <> 200 then 1 ELSE 0 END) vodafone_unsuccessful,
sum(case when rs.operator = 'vodafone' and rs.url_response_code = 200 then rs.msg_cost ELSE 0 END)/100 vodafone_successful_cost,
sum(case when rs.operator = 'vodafone' AND rs.url_response_code <> 200 then rs.msg_cost ELSE 0 END)/100 vodafone_unsuccessful_cost,
sum(case when rs.operator = 'vodafone-idea' and rs.url_response_code = 200 then 1 ELSE 0 END) vodafone_idea_successful,
sum(case when rs.operator = 'vodafone-idea' AND rs.url_response_code <> 200 then 1 ELSE 0 END) vodafone_idea_unsuccessful,
sum(case when rs.operator = 'vodafone-idea' and rs.url_response_code = 200 then rs.msg_cost ELSE 0 END)/100 vodafone_idea_successful_cost,
sum(case when rs.operator = 'vodafone-idea' AND rs.url_response_code <> 200 then rs.msg_cost ELSE 0 END)/100 vodafone_idea_unsuccessful_cost,
sum(case when rs.operator = 'reliance-jio' and rs.url_response_code = 200 then 1 ELSE 0 END) reliance_jio_successful,
sum(case when rs.operator = 'reliance-jio' AND rs.url_response_code <> 200 then 1 ELSE 0 END) reliance_jio_unsuccessful,
sum(case when rs.operator = 'reliance-jio' and rs.url_response_code = 200 then rs.msg_cost ELSE 0 END)/100 reliance_jio_successful_cost,
sum(case when rs.operator = 'reliance-jio' AND rs.url_response_code <> 200 then rs.msg_cost ELSE 0 END)/100 reliance_jio_unsuccessful_cost,
COUNT(rs.id) counts,
SUM(rs.msg_cost)/100 total_costs
FROM responses rs LEFT JOIN users u ON rs.client_id = u.id
WHERE rs.responseon >= SUBDATE(CURDATE(), 1) AND rs.responseon < CURDATE()
GROUP BY u.id, DATE_FORMAT(rs.responseon, '%Y-%m-%d'), rs.url_response_code;
OHA YOOOO