(select Evt_Vs_Pri_DOW_Trend.DAYOFWEEK as Day, sum(Evt_Vs_Pri_DOW_Trend.EVENT_COUNT)/(CASE WHEN ${noofweeks}>0 THEN ${noofweeks} ELSE 1 END) as Total_Events, 'Historical' as Type from Evt_Vs_Pri_DOW_Trend inner join Resources on Evt_Vs_Pri_DOW_Trend.RID = Resources.RESOURCEID group by Day,Type order by position(DAYOFWEEK in 'SunMonTueWedThuFriSat')) union  all (select to_char(Evt_Count_Dy.HOUR,'Dy') as Day,sum(Evt_Count_Dy.EVENT_COUNT) as Total_Events, 'Last Week'  as Type from Evt_Count_Dy inner join Resources on Evt_Count_Dy.RID = Resources.RESOURCEID  where ( Evt_Count_Dy.HOUR BETWEEN (localtimestamp(0) - INTERVAL '7 DAY') AND localtimestamp(0) ) group by Day,Type)