本文介紹了你如何在 SQL 中找到去年相同的工作日?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
通常在銷售報告等中,您需要將這一天與去年的同一天進行比較,但要基于相同的工作日",而不是每月的某天".
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 日和星期四.我想查看今天的銷售額與去年同一個星期四的銷售額(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 中做到這一點?
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)
這篇關于你如何在 SQL 中找到去年相同的工作日?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!