Advertisement
ski900

SO.com_query_attempt_1

Nov 9th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.09 KB | None | 0 0
  1. SELECT att.datekey datekey, att.TimeKey timekey, att.Weekday_Name, att.Peak_Hours peak_hours, att.maxatt
  2. FROM (
  3.         SELECT dt.datekey, dt.timekey, dt.Weekday_Name, dt.peak_hours, Avg_T_Dur_Traffic maxatt
  4.         FROM [cat].Analytics_AvgTimes t
  5.         INNER JOIN cat.dim_date dt ON dt.DateKey = t.DateKey AND dt.TimeKey = t.TimeKey
  6.      ) att
  7. INNER JOIN cat.dim_date dt ON att.DateKey = dt.DateKey AND att.TimeKey = dt.TimeKey
  8. INNER JOIN(
  9.             SELECT dt.DateKey datekey, dt.TimeKey timekey, dt.Peak_Hours peak_hours, dt.Weekday_Name weekday_name,         
  10.                         MAX(avg_t_dur_traffic)/60 MaxAtt
  11.             FROM cat.Analytics_AvgTimes att
  12.             INNER JOIN cat.Dim_Date dt ON att.datekey = dt.DateKey AND att.TimeKey = dt.TimeKey
  13.             GROUP BY dt.DateKey, dt.Peak_Hours, dt.Weekday_Name, dt.timekey
  14.           ) mt ON att.DateKey = mt.datekey AND att.TimeKey = mt.timekey AND att.peak_hours = mt.peak_hours AND att.maxatt = mt.MaxAtt
  15.                     AND att.Weekday_Name = mt.Weekday_Name
  16. --where att.DateKey = '20170523' and att.Peak_Hours <> 'off_peak'
  17. GROUP BY att.datekey, att.peak_hours, att.weekday_name, att.MaxAtt, att.TimeKey
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement