MySQL SUM与分组日期

时间:2016-09-30 07:51:24

标签: php mysql sum case

如何获取带分组日期的数据价格?

SELECT store.date, store.pic, owner.name, 
SUM (CASE WHEN [>>GROUPED store.date<<] THEN store.price) AS total_price
FROM store
JOIN owner 
ON store.pic = owner.name GROUP BY store.date

我希望显示如下:

+-------------+------+------------+
| date        | name |  price     | 
+-------------+------+------------+
| 2016-09-30  | John | 100000.00  |
| 2016-09-29  | Rey  | 125000.00  | 
+-------------+------+------------+

1 个答案:

答案 0 :(得分:1)

试试这可能会对你有帮助,

 SELECT store.date, store.pic, owner.name,SUM(store.price) AS total_price
 FROM store
 JOIN OWNER ON store.pic = owner.name
 GROUP BY store.date

我无法理解您在查询中使用case语句的原因