SQL把日期轉換為季度來作查詢

2021-05-24 04:48:06 字數 477 閱讀 5234

select season = case when month(日期) in (1,2,3) then '一季度'

when  month(日期) in (4,5,6) then '二季度'

when  month(日期) in (7,8,9) then '三季度'

when  month(日期) in (10,11,12) then '四季度' end ,

count(*)

from tablename

group by    case when month(日期) in (1,2,3) then '一季度'

when  month(日期) in (4,5,6) then '二季度'

when  month(日期) in (7,8,9) then '三季度'

when  month(日期) in (10,11,12) then '四季度' end

查詢結果為 按季度分組後的各季度記錄數量

把int型別日期轉換為datetime型別日期

在維護乙個 原開發者儲存日期時,都是使用int資料型別,如20120218等。現insus.net獲取這個欄位做其它處理,得先需要把它們轉為datetime資料型別。因此產生以下這個user defined functions 自定義函式 create function dbo udf conver...

在SQL中直接把查詢結果轉換為JSON資料

引用自 在sql server2016版本之後的新特性中,利用for json path 可以將 內容轉成json字串,有自動轉化和指定格式等轉換。下面這篇中,已經有準備一些資料 ms sql server物件型別type 為前端服務,直接在sql把查詢結果轉換為json格式資料 實現這樣的功能,可...

使用MySQL內建函式把字串轉換為日期

mysql內建函式是很重要的一類函式,我們可以通過mysql內建函式把字串轉換為日期,下面就為您詳細介紹該方法,供您參考。在mysql裡面利用str to date 把字串轉換為日期。mysql內建函式例項 分隔符一致,年月日要一致 select str to date 02 25 1998 12 ...