我的查询是:
Select convert(varchar,dateadd(mi,tz.offset,cal.caldate),101) as caldate,
s.[off],
s.aban,
s.ans,
case when s.[off] - s.abn_in = 0 then 0 else 1 end as sla,
g.slgo
from calend cal left join
summ s on cal.caldate = dateadd(mi,tz.offset,s.arrdate)
inner join gol g on g.id = cal.id
left outer join zone tz on
tz.id = s.arrdate
输出:
caldate off aban ans sla slgo
04/01/2011 1 0 1 1 60
04/01/2011 2 0 2 1 30
03/12/2011 3 1 2 1 90
当我运行此查询时,我收到错误。我看到的问题是表区域和汇总是相互依赖的。我该如何解决这个问题?
答案 0 :(得分:2)
首先,我要说我不知道你在这个查询中做了什么,所以我的答案可能不是你正在寻找的解决方案。但是,如果您遇到的唯一问题是连接顺序,为什么不从区域tz开始,然后在这种情况下加入summ?
select
convert(varchar,dateadd(mi,tz.offset,cal.caldate),101) as caldate,
s.[off],
s.aban,
s.ans,
case when s.[off] - s.abn_in = 0 then 0 else 1 end as sla,
g.slgo
from
calend cal
cross join zone tz
left join summ s on cal.caldate = dateadd(mi,tz.offset,s.arrdate) and tz.id = s.arrdate
inner join gol g on g.id = cal.id
它不再是加入区域了......但这是必不可少的吗?