如何计算行数

时间:2016-01-18 13:22:52

标签: sql sql-server

我如何计算两个日期之间的行数。

SELECT Count(DATEDIFF(day, ReceiptDate,GETDATE()))
 As TotalDays 
 From JobDetails 
  Where Receiptdate Between DATEADD(day, -30, GETDATE()) and DATEADD(day, -90, GETDATE())
   AND RepairCompleted='N'
  Group By ReceiptDate

例如,我想检查未完成的工作计数30到90天。

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT Count(*) As TotalDays 
FROM JobDetails 
WHERE Receiptdate >= DATEADD(day, -90, GETDATE()) 
AND Receiptdate <= DATEADD(day, -30, GETDATE())
AND RepairCompleted='N'