SQL查詢最近幾年、幾月的資料

來源:互聯網
上載者:User
select DateAdd(Month,-3,getdate()) --返回一個時間,根據這個時間點去查詢想要的資料即可--DateAdd函數的詳細說明:--DateAdd(interval,   number,   date)--interval   必選。字串運算式,表示要添加的時間間隔。--yyyy   年--q   季度--m   月--y   一年的日數--d   日--w   一周的日數--ww   周--h   小時--n   分鐘--s   秒--number   必選,數值運算式。--表示要添加的時間間隔的個數。數值運算式可以是正數(得到未來的日期)或負數(得到過去的日期)。--date   必選。標識查詢時的對比時間,getdate()在SQL中說明是現在的時間 。--例子:Select DateAdd(Month,-3,getdate())  --以目前時間為準,返回三個月之前的一個時間點Select DateAdd(yyyy,-3,getdate())   --以目前時間為準,返回三年之前的一個時間點Select DateAdd(Month,3,getdate())   --以目前時間為準,返回三個月之後的一個時間點

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.