Thank you Dieter! I wound up using the calendar to divide by the the number of days in the date range, rather than only days with data. You've helped me tremendously!
SELECT
dt.dayofweek,
calls."hour",
cast(calls.CountbyDayofWeek as decimal(15,3)) / dt.num_of_days as AVG_COUNT
from
(select
CASE day_of_week
WHEN 1 THEN 'Sun' WHEN 2 THEN 'Mon' WHEN 3 THEN 'Tue' WHEN 4 THEN 'Wed' WHEN 5 THEN 'Thu' WHEN 6 THEN 'Fri' WHEN 7 THEN 'Sat' END as DayofWeek,
count(*) as num_of_days
from sys_calendar.calendar
where calendar_date Between '2013-03-07' AND '2013-05-07'
group by 1
)dt
join
(SELECT
EXTRACT(HOUR FROM case_creation_ts) AS "hour" ,
Count (*) as CountbyDayofWeek,
CASE ((cast(case_creation_ts as date) - Date '1900-01-01') Mod 7) +1
WHEN 7 THEN 'Sun'
WHEN 1 THEN 'Mon'
WHEN 2 THEN 'Tue'
WHEN 3 THEN 'Wed'
WHEN 4 THEN 'Thu'
WHEN 5 THEN 'Fri'
WHEN 6 THEN 'Sat' END as DayofWeek
FROM calls_table
Group by 1,3
)calls on dt.dayofweek = calls.dayofweek
order by 1,2
I used the suggestion from Ulrich in a previous post, from:
http://forums.teradata.com/forum/database/determine-average-count-by-day-of-week
Thank you Dieter! I wound up using the calendar to divide by the the number of days in the date range, rather than only days with data. You've helped me tremendously!
I used the suggestion from Ulrich in a previous post, from:
http://forums.teradata.com/forum/database/determine-average-count-by-day-of-week