27,579
社区成员
发帖
与我相关
我的任务
分享
直接这样? OR的效率好像不高.
select A.Id, datediff(n,A.CreatedOn, B.CreatedOn) as Duration from Table A with (nolock)
left join Table B with (nolock) on A.Id = B.Id
where A.Type = 1 and ( B.Type = 2 or B.Type = 3)
union all
select A.Id, datediff(n,A.CreatedOn, B.CreatedOn) as Duration from Table A with (nolock)
left join Table B with (nolock) on A.Id = B.Id
where (A.Type = 2 or A.Type = 3) and ( B.Type = 4)
union all
select A.Id, datediff(n,A.CreatedOn, B.CreatedOn) as Duration from Table A with (nolock)
left join Table B with (nolock) on A.Id = B.Id
where A.Type = 1 and B.Type = 5
Create proc [dbo].[UserAdd]
(
@datetime1 datetime,
@datetime2 datetime,
@datetime3 datetime
)
as
begin
...
end
select A.Id, datediff(n,A.CreatedOn, B.CreatedOn) as Duration from Table A with (nolock)
left join Table B with (nolock) on A.Id = B.Id
where (A.Type = 1 and ( B.Type = 2 or B.Type = 3)) or ((A.Type = 2 or A.Type = 3) and ( B.Type = 4))
or (A.Type = 1 and B.Type = 5)