590
社区成员
发帖
与我相关
我的任务
分享
[select '好像不行啊' as a]
[code=SQL][/select '好像不行啊' as a]
[code=SQL]
select '好像不行啊' as awith cte as
(
select id=row_number()over(partition by t1.order_id order by t3.calltime),
t1.order_id, t1.add_time, diff=datediff(second, t1.add_time, t3.calltime)
from t1
join t2 on t1.tourist_id=t2.tourist_id
join t3 on t2.tel1=t3.tel or t2.tel2=t3.tel or t2.tel2=t3.tel or t2.tel2=t3.tel
)
select order_id,
[1] = max(case id when 1 then diff end),
[2] = max(case id when 2 then diff end),
[3] = max(case id when 3 then diff end)
from cte group by order_id