这是我的桌子,我能得到这个结果吗?每个用户都有积分,我必须显示当月,当年获得的用户积分数
谢谢。
--------------------------------
| userId | points | date |
--------------------------------
| 1 | 5 | 8/25/2013 |
| 1 | 3 | 8/16/2013 |
| 1 | 2 | 8/01/2013 |
| 1 | 2 | 9/25/2013 |
| 1 | 5 | 8/25/2013 |
| 1 | 3 | 2/16/2012 |
| 2 | NULL | NULL |
| 2 | NULL | NULL |
--------------------------------
他们的结果应该是这样的:
---------------------------------------------------
| userId | CurrentMonthpoints | CurrentYearPoints |
---------------------------------------------------
| 1 | 15 | 17 |
| 2 | NULL | NULL |
---------------------------------------------------
我的请求 :
SELECT userId,
(SELECT sum(points)
from tbl_points
WHERE PointsDate between '8/1/2013' and '8/31/2013') AS CurrentMonthPoints,
(SELECT distinct SUM(points)
from tbl_points
WHERE PointsDate between '1/1/2014' and '12/31/2014' ) AS CurrentYearPoints
from tbl_user_performance_points
但我的查询错误地显示为:
---------------------------------------------------
| userId | CurrentMonthpoints | CurrentYearPoints |
---------------------------------------------------
| 1 | 15 | 17 |
| 2 | 15 | 17 |
---------------------------------------------------
提前谢谢