【发布时间】:2016-09-30 07:51:23
【问题描述】:
如何获取分组日期的数据价格?
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 category_id, sum(case when category_id=2 then product_min_price else 0 end) as ss, sum(case when category_id =1 then product_min_price else 0 end) as ttt from myzf.products