比较复杂的SQL语句

lpgx1981 2006-12-18 05:23:24
一个天气预报的语句,weather表中中一个字段名是date,表示是录入信息的时间,天气预报要求每天下午4点开始更新,今天4点以后更新的数据,要求是在几天下午4点以后到明天下午5点以前可以看到

自己写的sql语句:
select * from weather where

date> getdate()-1
and
(
(DATEPART(day,date)=DATEPART(day,getdate())
and DATEPART(hour,date)>17 )
or
(DATEPART(day,date)=(DATEPART(day,getdate())+1)
and DATEPART(hour,date)<16 )
)

但是我录入的时间是17号16:30,但是当我在18号17点以前看不到我录入的信息
...全文
282 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lpgx1981 2006-12-19
  • 打赏
  • 举报
回复
非常感谢啊,来,亲一个!!!
lpgx1981 2006-12-19
  • 打赏
  • 举报
回复
非常感谢
CrazyFor 2006-12-18
  • 打赏
  • 举报
回复
select * from weather where
where cast(convert(char(10),dtae+1,120)+' 17:00:00' as datetime)>getdate()

这样应该对了~~~
CrazyFor 2006-12-18
  • 打赏
  • 举报
回复
select * from weather where
date+1 > cast(convert(char(10),getdate()-1,120)+' 17:00:00' as datetime)


感觉是这么回事。:)
libin_ftsate 2006-12-18
  • 打赏
  • 举报
回复
没仔细看,也许还有问题
chd2001 2006-12-18
  • 打赏
  • 举报
回复
select * from weather where

date> getdate()-1
and
(
(DATEPART(day,date)=DATEPART(day,getdate())
and DATEPART(hour,date)<17 ) ------------------------
or
(DATEPART(day,date)=(DATEPART(day,getdate())+1)
and DATEPART(hour,date)<16 )
)
libin_ftsate 2006-12-18
  • 打赏
  • 举报
回复
select * from weather where
date> dateadd(hour,-25,getdate())
and
(
(DATEPART(day,date)=DATEPART(day,getdate())
and DATEPART(hour,date)>17 )
or
(DATEPART(day,date)=(DATEPART(day,getdate())+1)
and DATEPART(hour,date)<16 )
)

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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