MYSQL - 使用select语句进行内连接以获取Sum

时间:2013-03-22 07:06:49

标签: mysql sql sum inner-join

现在我有以下查询:

SELECT
ui.email,
ui.userid,
SUM(ep.earnPoints),
ep.add_date
from earn_points as ep 
INNER JOIN user_info as ui on ep.userid on ui.userid 
where DATE(rc.add_date) = '2012-03-22';

我想通过各自的电子邮件获取个人使用的总积分数

所以我的最终输出应该如下:

-----------------------------------------------------------
userid      email                   earnPoints      date        
1           testuser@gmail.com      45              2012-03-22
2           testuser123@gmail.com   10              2012-03-22
3           testuser145@gmail.com   18              2012-03-22
-----------------------------------------------------------

2 个答案:

答案 0 :(得分:0)

你只是错过了小组:

SELECT
ui.email,
ui.userid,
SUM(ep.earnPoints),
ep.add_date
from earn_points as ep 
INNER JOIN user_info as ui on ep.userid on ui.userid 
where DATE(rc.add_date) = '2012-03-22'
Group By ui.email,ui.userid,ep.add_date

答案 1 :(得分:0)

SELECT
ui.email,
ui.userid,
SUM(ep.earnPoints),
ep.add_date
from earn_points as ep 
INNER JOIN user_info as ui on ep.userid = ui.userid 
where DATE(rc.add_date) = '2012-03-22' Group By ui.email,ui.userid,ep.add_date;