繁体   English   中英

MySQL SUM与分组日期

[英]MySQL SUM With Grouped Date

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

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  | 
+-------------+------+------------+

试试这个可能对您有帮助,

 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语句

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM