I am making a mistake placing the self or left join. the main purpose of this querry is to bring back weekid, legid, avg final duration, volume, 95% of volume and 95th-tile of the avg duration.
I have the following code:
Select
b. weekid,
a.LegID,
avg (Final_Duration) Avg_Final_Duration,
count(a.itemID) Volume,
cast (0.95 * Volume as integer) as Volume_95
from table1 a
join table2 b
on a.receivedate=b.PeriodID
where
a.Final_Duration is not null
Left join (select avg(ts.final_duration)
from table1 ts
join table2 tm
on ts.receivedate=tm.PeriodID
where
ts.Final_Duration is not null
and
ts. X_tile >= 95 group by ts.LEGID, tm.WeekID) as Findur_95
group by a.LegID, b.weekID
order by WeekID, a.LegID ASC
please help!!!
Forums: