首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

又是关于时间的查询!该如何解决

2012-02-15 
又是关于时间的查询!IDdateF44FC345B10F0502006/01/0321:29:24F44FC38A910F0502006/01/0701:25:38F44FC3EE

又是关于时间的查询!
ID                                           date
F44FC345B10F0502006/01/03   21:29:24
F44FC38A910F0502006/01/07   01:25:38
F44FC3EE510F0502006/01/03   23:32:22
F488035EB10F0502006/01/05   08:38:50
F50B42AFC10F0502006/01/03   13:35:32
F50B42AFC10F0502006/01/08   23:55:12

比如
以上数据,想查询12:00~20:00的ID(不管日期,只看具体时间)
谢谢啦!


[解决办法]
select *
from table
where datepart(date,hh) > =12 and datepart(date,hh) <= 20
[解决办法]
select *
from table
where datepart(date,hh) BETWEEN 12 and 20
[解决办法]
select * from table
where substrint(convert(varchar,[date],120),12,16) between '12:05 ' and '20:15 '
[解决办法]
select * from table
where substring(convert(varchar,[date],120),12,16) between '12:05 ' and '20:15 '

[解决办法]
select *
from table
where datepart(date,hh) > =12 and datepart(date,hh) < 21

[解决办法]
--或者
select * from table
where substrint(convert(varchar,[date],108),1,5) between '12:05 ' and '20:15 '

[解决办法]
select *
from table
where DATEPART(hour, [date]) between 12 and 20

热点排行
Bad Request.