Sample Header Ad - 728x90

Problem of SUM of the SUM

1 vote
2 answers
199 views
When I execute my query I have always the same problem : year_created|month_created|loc_id_1|loc_id_2|loc_id_3|Total ------------------------------------------------------------ 2016 | 7 | 0 | 0.40 | 0 0.40 2016 | 7 | 0.50 | 0 | 0 0.50 2016 | 7 | 0 | 0 | 0.30 0.30 How I can combine to have a single line : year_created|month_created|loc_id_1|loc_id_2|loc_id_3| ------------------------------------------------------- 2016 | 7 | 0.50 | 0.40 | 0.30 This is my query : SELECT MONTH(created_at) as month_created, YEAR(created_at) as year_created, 1 - SUM(price)/SUM(order_total) as Total, CASE loc_id WHEN 1 THEN 1 - SUM(price)/SUM(order_total) ELSE 0 END ) AS 'loc_id_1', CASE loc_id WHEN 2 THEN 1 - SUM(price)/SUM(order_total) ELSE 0 END ) AS 'loc_id_2', CASE loc_id WHEN 3 THEN 1 - SUM(price)/SUM(order_total) ELSE 0 END ) AS 'loc_id_3' FROM data_price WHERE YEAR(created_at) = YEAR(NOW()) GROUP BY year_created, month_created ORDER BY year_created asc, month_created desc
Asked by Sarah (121 rep)
Jul 12, 2016, 08:20 AM
Last activity: Mar 8, 2019, 03:00 PM