I’m basically trying to sum up the values of a specific column. RIght now my query looks like this:
SELECT
DATE(paid_at) AS day,
(SELECT sum(shipping_costs) from orders where shipping_method = 'mondial_relais' and DATE(paid_at) = day) as mr_revenue_real
FROM orders
WHERE MONTH(paid_at) = 10
AND YEAR(paid_at) = 2011
GROUP BY day;
I want to replace the subquery for mr_revenue_real to improve performance but I’m not sure how to do that. This is what I had in mind:
sum(case when hipping_method = 'mondial_relais' and DATE(paid_at) = day then 1 end) as mr_revenue_realbut this won’t work because I’m not specifying anywhere that I need the sum of the shipping_costs.
Any ideas?
the full query: