当前位置:首页 » 编程语言 » 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

如果你的这两个列有些特殊性,或者两个列没有分开,可以单独联系,我帮你解决(相对来说复杂点)

标签:作文经典 上一篇:带苦干的词语 形容苦干的词语 下一篇:快板台词护士夸赞美 夸赞幼儿园快板台词

热点内容
pythonforinkeys 发布:2024-05-19 01:55:44 浏览:792
电脑如何局域网共享文件夹 发布:2024-05-19 01:25:01 浏览:68
手机存储越大性能越好吗 发布:2024-05-19 01:14:28 浏览:176
我的世界hyp服务器怎么玩 发布:2024-05-19 00:51:25 浏览:801
手机如何解压百度云文件 发布:2024-05-19 00:32:24 浏览:905
centos使用python 发布:2024-05-18 23:39:48 浏览:869
幻影天龙脚本 发布:2024-05-18 23:38:17 浏览:714
编程的py 发布:2024-05-18 23:36:22 浏览:76
安卓系统怎么改序列号 发布:2024-05-18 23:28:16 浏览:785
c语言中实数 发布:2024-05-18 23:21:03 浏览:897