标签:images lock group alt indicator img hid ted time
现有数据如上图所示,要求统计出日期相同的Count总数,并且加一列统计前面日期Count的总和
1 SELECT SUM([Count]) AS DayTotal, SUM(SUM([Count])) over (order by [Datetime]) Total, [datetime] FROM Table_3 2 GROUP BY [DateTime] 3 ORDER BY [DateTime] DESC
结果如下:
Total列是日期小于当前行的DayTotal列的总和;比如第三行 日期是2017-02-02,这行的Total就是当前行的DayTotal + 上一行(日期为2017-02-01)的Total之和
注:上面的SQL语句中 Over 是关键,少了统计不出来
标签:images lock group alt indicator img hid ted time
原文地址:http://www.cnblogs.com/lao-tang/p/6541784.html