0
根據當前日期,我需要設置WHERE
條件的情況。基於當前日期的SQL Server需要檢查WHERE條件下的日期範圍
select
count(id)
from
table1
case
when (DAY(GETDATE())) between 1 and 15
Then created_date between (getdate()-DAY(GETDATE())+1) and (getdate()+15-DAY(GETDATE()))
else created_date between (getdate()+16-DAY(GETDATE())) and (getdate()+31-DAY(GETDATE()))
End
但它不適用於我。
對於例如,
表1:
Id App_Name Created_Date
1 app1 2016-12-05
2 app2 2016-12-10
3 app3 2016-12-16
4 app4 2016-12-25
5 app5 2016-12-28
今天的日期是2016年12月15日,所以我需要2016年12月1日之間採取CREATED_DATE至2016年12月15日。
預期成果是 「2」
但是爲什麼'2016-12-05'不包含在結果集中,因爲它在範圍之內? –
2016-12-05也包括在內。前兩個記錄將被記錄下來。 – Srinivasan
簡單英語的要求是什麼?你是否在計算從月初到當前日期的記錄? –