简体   繁体   中英

Last Year’s YTD Number query

I need help getting the count of records for last year's YTD.

To get the records for this YTD numbers I have:

SELECT COUNT(columnname) 
FROM *** 
where "columnname" BETWEEN DATEADD(yy, DATEDIFF(yy,0,GETDATE()), 0) AND GETDATE() 
AND user_code IN ('0410', '0411')) as Ag

This give the total records for 01/01/2016-06/02/2016 (today's date) which is right now I need to get the same total but for last's YTD it would be for 01/01/2015-06/02/2015 please help.

为此,在两个都有GETDATE() ,只需将其替换为DATEADD(YEAR,-1,GETDATE())

WHERE [someColumn] BETWEEN DATEADD(yy, DATEDIFF(yy,0,DATEADD(YEAR,-1,GETDATE())), 0) AND DATEADD(YEAR,-1,GETDATE()) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM