我有一条SQL语句(MS SQL Server 2005),可以对一些记录上的日期差异进行简单的计算。我也想返回DATEDIFF的总数/总和。
SELECT (DATEDIFF(day, StartDate, EndDate)+1) AS myTotal FROM myTable WHERE (Reason = '77000005471247')
如何从myTotal获取总和?这就是我要返回的全部。
提前致谢
如果包含其他任何列,则还需要包含GROUP BY子句
SELECT AnotherColumn, SUM(DATEDIFF(day, StartDate, EndDate)+1) AS myTotal FROM myTable WHERE (Reason = '77000005471247') GROUP BY AnotherColumn