如何解决使用方程datediff过滤数据的困惑
我在编写查询时遇到了麻烦,该查询将使用或条件来计算30分钟或120分钟的小时数,但是我一直遇到错误。我为方程式使用了别名。为方程式设置or条件的正确方法是什么。
-今天,当子工作进入压区时,不再压在压区中了,压在压区中的时间长了
SELECT DATEDIFF(minute,begintime,aftertime) difference
FROM [ABC].[dbo].[timerecords] (nolock)
where begintime > '1994-08-11'
and aftertime is not null
-- you can not use alias
DATEDIFF(minute,aftertime) in (30 or 120)
解决方法
将查询打包为派生表:
select * from
(
SELECT DATEDIFF(minute,begintime,aftertime) difference
FROM [ABC].[dbo].[timerecords] (nolock)
where begintime > '1994-08-11'
and aftertime is not null
) dt
where difference in (30,120)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。