指定星期的SQL查询



我需要在2021年5月至2021年8月期间从周日晚上7点到周五早上5点检查记录。在where条件下怎么写呢?

下面的查询是针对3个月的,但我想要从周日晚上7点到周五早上5点。

l1.[PickupTime] between '2021/05/01 19:00:00' and '2021/09/01 05:00:00'
你能帮我一下吗?

嗯…我想你需要:

where l1.[PickupTime] between '2021-05-01' and '2021-09-02' and
((datename(weekday, l1.[PickupTime]) = 'Sunday' and 
time(l1.[PickupTime]) >= '19:00:00'
) or
(datename(weekday, l1.[PickupTime]) in ('Monday', 'Tuesday', 'Wednesday', 'Thursday') or
(datename(weekday, l1.[PickupTime]) = 'Friday' and
time(l1.[PickupTime]) < '05:00:00'
)
)

相关内容

  • 没有找到相关文章

最新更新