本文介紹了你如何在 SQL 中找到去年相同的工作日?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
通常在銷售報(bào)告等中,您需要將這一天與去年的同一天進(jìn)行比較,但要基于相同的工作日",而不是每月的某天".
Often in sales reports and so on you need to compare this day to the same day last year, but based on the same "weekday", not "day of month".
例如,今天是 2013 年 6 月 20 日和星期四.我想查看今天的銷售額與去年同一個(gè)星期四的銷售額(2012 年 6 月 21 日,而 2012 年 6 月 20 日是星期三).
So for example, today is the 20th June 2013 and a Thursday. I want to see sales for today, versus the same THURSDAY last year (21st June 2012, as opposed to 20th June 2012 which was a Wednesday).
如何在 T-SQL 中做到這一點(diǎn)?
How can this be done in T-SQL?
推薦答案
DECLARE @now Date
SET @now = '2013-06-20' -- your example
SELECT DATEADD(week, -52, @now)
SET @now = '2012-06-21' -- leap year test
SELECT DATEADD(week, -52, @now)
這篇關(guān)于你如何在 SQL 中找到去年相同的工作日?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!