當前位置:首頁 » 編程語言 » sql按小時分組

sql按小時分組

發布時間: 2024-05-05 13:26:25

Ⅰ 時間段分組的sql語句請教

select case when convert(char(2),lTime,108)>=0 and convert(char(2),lTime,108)<=1
then '00:00-01:00'
when convert(char(2),lTime,108)>=1 and convert(char(2),lTime,108)<=2
then '01:00-02:00'
when convert(char(2),lTime,108)>=2 and convert(char(2),lTime,108)<=3
then '02:00-03:00'
when convert(char(2),lTime,108)>=3 and convert(char(2),lTime,108)<=4
then '03:00-04:00'
when convert(char(2),lTime,108)>=4 and convert(char(2),lTime,108)<=5
then '04:00-05:00'
when convert(char(2),lTime,108)>=5 and convert(char(2),lTime,108)<=6
then '05:00-06:00'
when convert(char(2),lTime,108)>=6 and convert(char(2),lTime,108)<=7
then '06:00-07:00'輪核源
when convert(char(2),lTime,108)>=7 and convert(char(2),lTime,108)<=8
then '臘態07:00-08:00'
when convert(char(2),lTime,108)>=8 and convert(char(2),lTime,108)<=9
then '08:00-09:00'
when convert(char(2),lTime,108)>=9 and convert(char(2),lTime,108)<=10
then '09:00-10:00'
when convert(char(2),lTime,108)>=10 and convert(char(2),lTime,108)<=11
then '10:00-11:00'
when convert(char(2),lTime,108)>=11 and convert(char(2),lTime,108)<=12
then '11:00-12:00'
when convert(char(2),lTime,108)>=12 and convert(char(2),lTime,108)<=13
then '12:00-13:00'
when convert(char(2),lTime,108)>=13 and convert(char(2),lTime,108)<=14
then '氏清13:00-14:00'
when convert(char(2),lTime,108)>=14 and convert(char(2),lTime,108)<=15
then '14:00-15:00'
when convert(char(2),lTime,108)>=15 and convert(char(2),lTime,108)<=16
then '15:00-16:00'
when convert(char(2),lTime,108)>=16 and convert(char(2),lTime,108)<=17
then '16:00-17:00'
when convert(char(2),lTime,108)>=17 and convert(char(2),lTime,108)<=18
then '17:00-18:00'
when convert(char(2),lTime,108)>=18 and convert(char(2),lTime,108)<=19
then '18:00-19:00'
when convert(char(2),lTime,108)>=19 and convert(char(2),lTime,108)<=20
then '19:00-20:00'
when convert(char(2),lTime,108)>=20 and convert(char(2),lTime,108)<=21
then '20:00-21:00'
when convert(char(2),lTime,108)>=21 and convert(char(2),lTime,108)<=22
then '21:00-22:00'
when convert(char(2),lTime,108)>=22 and convert(char(2),lTime,108)<=23
then '22:00-23:00'
when convert(char(2),lTime,108)>=23 and convert(char(2),lTime,108)<=24
then '23:00-00:00'
end as 時間段,sum(lNum)合計
from listtable group by
case when convert(char(2),lTime,108)>=0 and convert(char(2),lTime,108)<=1
then '00:00-01:00'
when convert(char(2),lTime,108)>=1 and convert(char(2),lTime,108)<=2
then '01:00-02:00'
when convert(char(2),lTime,108)>=2 and convert(char(2),lTime,108)<=3
then '02:00-03:00'
when convert(char(2),lTime,108)>=3 and convert(char(2),lTime,108)<=4
then '03:00-04:00'
when convert(char(2),lTime,108)>=4 and convert(char(2),lTime,108)<=5
then '04:00-05:00'
when convert(char(2),lTime,108)>=5 and convert(char(2),lTime,108)<=6
then '05:00-06:00'
when convert(char(2),lTime,108)>=6 and convert(char(2),lTime,108)<=7
then '06:00-07:00'
when convert(char(2),lTime,108)>=7 and convert(char(2),lTime,108)<=8
then '07:00-08:00'
when convert(char(2),lTime,108)>=8 and convert(char(2),lTime,108)<=9
then '08:00-09:00'
when convert(char(2),lTime,108)>=9 and convert(char(2),lTime,108)<=10
then '09:00-10:00'
when convert(char(2),lTime,108)>=10 and convert(char(2),lTime,108)<=11
then '10:00-11:00'
when convert(char(2),lTime,108)>=11 and convert(char(2),lTime,108)<=12
then '11:00-12:00'
when convert(char(2),lTime,108)>=12 and convert(char(2),lTime,108)<=13
then '12:00-13:00'
when convert(char(2),lTime,108)>=13 and convert(char(2),lTime,108)<=14
then '13:00-14:00'
when convert(char(2),lTime,108)>=14 and convert(char(2),lTime,108)<=15
then '14:00-15:00'
when convert(char(2),lTime,108)>=15 and convert(char(2),lTime,108)<=16
then '15:00-16:00'
when convert(char(2),lTime,108)>=16 and convert(char(2),lTime,108)<=17
then '16:00-17:00'
when convert(char(2),lTime,108)>=17 and convert(char(2),lTime,108)<=18
then '17:00-18:00'
when convert(char(2),lTime,108)>=18 and convert(char(2),lTime,108)<=19
then '18:00-19:00'
when convert(char(2),lTime,108)>=19 and convert(char(2),lTime,108)<=20
then '19:00-20:00'
when convert(char(2),lTime,108)>=20 and convert(char(2),lTime,108)<=21
then '20:00-21:00'
when convert(char(2),lTime,108)>=21 and convert(char(2),lTime,108)<=22
then '21:00-22:00'
when convert(char(2),lTime,108)>=22 and convert(char(2),lTime,108)<=23
then '22:00-23:00'
when convert(char(2),lTime,108)>=23 and convert(char(2),lTime,108)<=24
then '23:00-00:00' end
--表是ListTable 時間欄位lTime,數量欄位lNum

Ⅱ sql語句時間排序 sql語句按照時間排序

SQL按時間排序

select * from MyTable Order By ModifyTime Desc

按修改的時間倒序排列

如果是知道最後一次是某天,加上條件

select * from MyTable Where DateDiff(day,ModifyTime,GetDate)=0 Order By ModifyTime Desc

sql 排序,order by 按時間

sql排序是指定時間欄位才能按照時間排序,asc默認升序,desc默認降序。

ORDER BY 語句

ORDER BY 語句用於根據指定的列對結果集進行排序。

ORDER BY 語句默認按照升序對記錄進行排序。

如果您希望按照降序對記錄進行排序,可以使用 DESC 關鍵字。

比如要排序:

select date from tablename order by date desc

按date降序排列。

SQL語句怎嘩租輪么寫?先按時間排序,再按姓名排序?

將欄位依次寫在order by 後面即可 , 中間用逗號隔開

select * from 表 order by time , name

select * from 表 order by time asc , name asc

select * from 表 order by time desc , name desc

select * from 表 order by time asc , name desc

select * from 表 order by time desc , name asc

(注: asc 表示升序 , desc表示降序 , 未明確寫明排序方式時默認是升序 )

與之類似的語型族法是 group by , 按多個欄位分組時 , 也是依次將多個欄位寫在group by 的後面 , 並用逗號隔開 , 範例如下:

select time , name , sum(*) from 表 group by time , name

怎樣用SQL語句 按日期進行從高到低進行排序

用SQL語句按日期進行從高到低進行排序:select * from tmp order by time desc;

結構化查詢語言(英文簡稱:SQL)是一種特殊目的的編程語言,是一種資料庫查詢和程序設計語言,用於存取數據以及查詢、更新和管理關系資料庫系統;同時也是資料庫腳本文件的擴展名。

結構化查詢語言是高級的非過程化編程語言,允許用戶在高層數據結構上工作。它不要求用戶指定對數據的存放方法,也不需要用戶了解具體的數據存放方式,所以具有完全不同底層結構的不同 資料庫系統,,可以使用相同的結構化查詢語言作為數據輸入與管理的介面。結構化查詢語言語句可以嵌套,這使它具有極大的靈活性和強大的功能。

標簽:作文經典 上一亂信篇:帶苦乾的詞語 形容苦乾的詞語 下一篇:快板台詞護士誇贊美 誇贊幼兒園快板台詞

sql語句的根據日期排序問題!

這個問題的原因是你的time 不是datetime 應該是varchar型.

改成這個.

sql="select id,title,content,class,img,time from info order by cast(time as datetime) desc"

就行了

怎樣用SQL語句 按日期進行從高到低進行排序呢~~

就是對日期進行倒排序

select * from tableName -- 假設你的表的名字是tableNameorder by dtcol desc; -- 假設你的日期欄位名是 dtcol; desc表示倒排序

sql語句:請問下面這sql怎麼往上加排序(降序)以時間為降序?

你這樣查詢出來就一個 符合你條件的記錄數

沒辦法排序啊?

如果打算按時間排序就別查個數了。。

select refund_id,addtime from refund where refund_audit=1 and f_user_uid ='" + userid + "'

order by addtime desc

//按時間倒敘

sql語句怎麼按照欄位1排序後再在本欄位內按時間排序

ORDER BY 後面可以寫多個

比如

ORDER BY Gender ASC, Age DESC, Name ASC

按照性別升序排列, 性別相同的按照年齡降序排列, 年齡再相同的按照姓名升序排列

SQL語句排序的問題

升序是 ASC,降序是 DESC

select * FROM a ORDER BY 錠 ASC,n DESC

sql 日期正序 時間倒序

這個問題,因為你日期和具體時間分別在兩列上,因此,是可以採用sql實現的。

SQL中增加order by語句如下:

ORDER BY 日期, 時間 DESC

如果你的這兩個列有些特殊性,或者兩個列沒有分開,可以單獨聯系,我幫你解決(相對來說復雜點)

標簽:作文經典 上一篇:帶苦乾的詞語 形容苦乾的詞語 下一篇:快板台詞護士誇贊美 誇贊幼兒園快板台詞

熱點內容
下載武裝突襲後怎麼進伺服器 發布:2024-05-18 22:56:17 瀏覽:823
c語言字元串大寫變小寫 發布:2024-05-18 22:56:16 瀏覽:436
重啟刪除的文件夾 發布:2024-05-18 22:34:11 瀏覽:636
視頻軟體源碼 發布:2024-05-18 22:22:24 瀏覽:428
安卓換蘋果sim卡去哪裡換 發布:2024-05-18 22:21:29 瀏覽:636
順豐薪資默認密碼是多少 發布:2024-05-18 22:15:04 瀏覽:790
瀏覽器打不開伺服器通信怎麼辦 發布:2024-05-18 21:32:22 瀏覽:961
創建存儲空間 發布:2024-05-18 21:20:57 瀏覽:122
sql日期和時間 發布:2024-05-18 21:16:19 瀏覽:143
安卓網頁怎麼截取 發布:2024-05-18 20:53:56 瀏覽:972