Mysql Sum and Group By Method

丶灬走出姿态 提交于 2019-12-25 00:55:49

问题


Input

Date            Points            Email

2012-07-01       5                 a@sample.com
2012-07-01       6                b@sample.com
2012-07-01       2                 c@sample.com

2012-07-02       5                d@sample.com

2012-07-03       8                e@sample.com
2012-07-03       7                 f@sample.com
2012-07-03       1                 y@sample.com

2012-07-04       3                x@sample.com
2012-07-04       2                f@sample.com

2012-07-05       3                g@sample.com
2012-07-05       9                b@sample.com

Output

Date            Points

2012-07-01       13
2012-07-02        5
2012-07-03       16
2012-07-04        5
2012-07-05       12

Suggest me an MySQL Query for output like the above


回答1:


try

 SELECT `date`, SUM(`Points`) AS sumPoint FROM table GROUP BY `date`

Note : dont forget to wrap date column with ` as DATE is reserve keyword of mySQL




回答2:


SELECT date, SUM(Points) AS sumPoint FROM table GROUP BY DATE(date)

Since date column might be datetime or date type in table



来源:https://stackoverflow.com/questions/11425458/mysql-sum-and-group-by-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!