我有一个表,它显示了员工生产的单位数量。它也有事务时间。
是否可以以这样的方式显示数据,即当当前时间为上午7时至下午3时,它只应显示在这段时间内发生的事务,然后当当前时间为下午3时,则只应显示在下午3时至11时之间的事务。
样本数据
units | name | TIME
-------------------------
10 | aa | 08:33:22
26 | bb | 10:33:22
36 | cc | 16:33:22
11 | dd | 18:33:22如果现在的时间是13:00,我想要的是上午7点到下午3点之间的所有事务,这只是前2点。但是当时间是15:00时,它应该自动显示下午3点到11点之间的所有事务。
发布于 2017-05-05 19:39:08
您可以使用where
where (datepart(hour, getdate()) between 7 and 14 and
datepart(hour, transactiondatetime) between 7 and 14
) or
(datepart(hour, getdate()) not between 7 and 14 and
datepart(hour, transactiondatetime) between 11 and 22
)https://stackoverflow.com/questions/43812577
复制相似问题