SQL语句读取晚上10点到早上8点之间的数据

Cjlu_B 2009-12-24 02:43:10
有一个时间字段记录的值是NOW() 包含了日期和时间 如何筛选
...全文
2637 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
lymmingv 2009-12-24
  • 打赏
  • 举报
回复
取昨晚10:00到今早8:00的数据
select * from [表名] where datepart(hh,getdate()-1)>='22' And datepart(hh,getdate())<=8
dawugui 2009-12-24
  • 打赏
  • 举报
回复
--含八点(到九点之前)
select * from tb where datepart(hh,dt) between 22 and 24 or datepart(hh,dt) between 0 and 8

--不含八点
select * from tb where datepart(hh,dt) between 22 and 24 or datepart(hh,dt) between 0 and 7

--小F-- 2009-12-24
  • 打赏
  • 举报
回复
select * from tb where datepart(hh,getdate())>='22' And datepart(hh,getdate())<=8
dawugui 2009-12-24
  • 打赏
  • 举报
回复
[Quote=引用楼主 cjlu_b 的回复:]
有一个时间字段记录的值是NOW() 包含了日期和时间 如何筛选
[/Quote]
select * from tb where datepart(hh,dt) between 22 and 24 or datepart(hh,dt) between 0 and 8

select * from tb where datepart(hh,dt) between 22 and 23 or datepart(hh,dt) between 0 and 7
jwdream2008 2009-12-24
  • 打赏
  • 举报
回复
select * from  [table] where datepart(hh,getdate())>=22 And datepart(hh,getdate())<=8
nianran520 2009-12-24
  • 打赏
  • 举报
回复
select * from tb
where convert(varchar(2),[date],108)<='08'
and convert(varchar(2),[date],108)>='22'
ACMAIN_CHM 2009-12-24
  • 打赏
  • 举报
回复
select * from datepart(hh,时间字段) between 8 and 22
lg3605119 2009-12-24
  • 打赏
  • 举报
回复

select * from tb where datepart(hh,时间字段)>=22 or datepart(hh,时间字段)<=8
jwdream2008 2009-12-24
  • 打赏
  • 举报
回复
select * from  [table] where datepart(hh,getdate())>='22' And datepart(hh,getdate())<=8
guguda2008 2009-12-24
  • 打赏
  • 举报
回复
SELECT * FROM [表名]
WHERE DATEPART(HH,[时间字段名]) BETWEEN 22 AND 24
OR DATEPART(HH,[时间字段名]) BETWEEN 0 AND 7
csdyyr 2009-12-24
  • 打赏
  • 举报
回复
datepart(hh,col) between 8 and 22
lg3605119 2009-12-24
  • 打赏
  • 举报
回复
select * from tb where datepart(hh,时间字段)>=10 and datepart(hh,时间字段)<=20 
sgtzzc 2009-12-24
  • 打赏
  • 举报
回复
mysql ?

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧