douduan3203
2016-09-30 07:51
浏览 153
已采纳

MySQL SUM与分组数据

How to get data Price 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

and i want to display like this :

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

图片转代码服务由CSDN问答提供 功能建议

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

  SELECT  store.date,store.pic,owner.name,
SUM(CASE WHEN [&gt;&gt; GROUPED store.date&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&n;  .name GROUP BY store.date 
   
 
 

我希望显示如下:

  + ---  ---------- + ------ + ------------ + \ N | 日期| 名字| 价格|  
 + ------------- + ------ + ------------ + \ N |  2016-09-30 | 约翰|  100000.00 | 
 |  2016-09-29 | 雷伊|  125000.00 |  
 + ------------- + ------ + ------------ + 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douguangxiang0363 2016-09-30 07:59
    已采纳

    Try this will may help you,

     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
    

    i can't understand why you used case statement in your query

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题