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