我需要列出每个月显示利润的城市的所有地区。
不知道如何将产品的计数值与子查询中的月份联系起来。
有人可以帮帮我吗?
SELECT
districts.id,
districts.name,
mmonth.m10
FROM districts
INNER JOIN
(SELECT
SUM(product_order.price_of_day * product_order.amount) AS m10
FROM product_order
INNER JOIN orders ON product_order.order_id = orders.id
WHERE MONTH(orders.date_time) = 10 ) mmonth
INNER JOIN cities ON cities.id = districts.city_id
WHERE cities.id = 2;
http://sqlfiddle.com/#!2/8fb34/4
看看我需要什么。
| id | name | m10 | m11 | m12 |
------------------------------------
| 3 | district 3 | 730 | 360 | 453 |
------------------------------------
| 4 | district 4 | 730 | 250 | 856 |
-------------------------------------
我将如何总结这样的月份?
| id | name | m10 | m11 | m12 | total |
---------------------------------------------
| 3 | district 3 | 730 | 360 | 453 | 1543 |
---------------------------------------------
| 4 | district 4 | 730 | 250 | 856 | 1836 |
---------------------------------------------