Skip to content
Advertisement

Hourly Total Average of a Group

I am trying to find the combined hourly average (travel time in this case) from a group of segments (code in the below) I get can get each segment individually but want to return sum all segments to produce one average for the group. My results give the average of all of the segments instead of the average combined time for all of the segments

Desired and Getting

Advertisement

Answer

Move the condition of the CASE expression to the WHERE clause.
Then group by Code also to get the averages of each Code and use SUM() window function to get the sum of all averages:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement