Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Average of volume by weekday and hour over range - forum topic by Dolm

$
0
0

 
I'm trying to calculate the average number of calls for a given weekday by hour of the day.  I've tried nesting aggregates byt it always comes out to 1, rather than the actual average.
 
Here's what the data looks like

creation_ts 	  weekday   hour
2013-04-01 20:27:41 Mon 	  8:00 PM
2013-04-02 15:56:55 Tue 	  3:00 PM
2013-04-03 11:54:33 Wed 	  11:00 AM
2013-04-03 23:51:22 Wed 	  11:00 PM
2013-04-04 17:53:45 Thu 	  5:00 PM
2013-04-05 10:56:53 Fri 	  10:00 AM
2013-04-05 15:19:25 Fri 	  3:00 PM
2013-04-06 03:56:32 Sat 	  3:00 AM
2013-04-06 14:58:46 Sat 	  2:00 PM

I'm needing to generate a result set that has an average number of calls for the hour for each weekday.
Something like

Weekday  00:00  01:00   02:00   03:00   ....  22:00   23:00
Sun          0      2       4       5            18      16
Mon
Tue
Wed
Thu
Fri
Sat

I tried using the following statement (by an example for dnoeth in previous similar post) but it only totals accross all days hour, rather than average
**Weekday and "hour" are columns from my temp table where I've extracted both from the timestamp

SELECT
weekday,
"hour",
avg(cnt) as CountByDayOfWeek
from
  (SELECT
   weekday,
   "hour",
   count(*) as cnt
  from
  calls_table
  group by 1,2
  )calls
group by 1,2

Any help is greatly appreciated!

Forums: 

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>