Exp Reason CreditAccounts Points
2012-01-30 02:11:58.830 Inactive 1 5
2012-01-31 02:11:58.827 Inactive 1 5
2012-02-01 02:12:02.130 Inactive 2 10
2012-02-03 02:11:58.820 Inactive 4 20
2012-02-03 02:12:02.120 Inactive 2 10
2012-02-04 02:12:02.113 Inactive 4 20
我应该得到这样的结果,我尝试分组,但没有什么工作像我需要的方式
Exp Reason CreditAccounts Points
2012-01-30 02:11:58.830 Inactive 1 5
2012-01-31 02:11:58.827 Inactive 1 5
2012-02-01 02:12:02.130 Inactive 2 10
2012-02-03 02:11:58.820 Inactive 6 30
2012-02-04 02:12:02.113 Inactive 4 20
对此的任何解决方案都会很棒 谢谢 王子
答案 0 :(得分:3)
看起来你正试图按日期分组?您忽略了包含有关表定义或要求的任何其他信息,但可能需要类似
的内容SELECT MIN(Exp) AS Exp,
Reason,
SUM(CreditAccounts) AS CreditAccounts,
SUM(Points) AS Points
FROM SomeTable
GROUP BY Reason, DATEDIFF(DAY, 0, Exp)