문제

I am trying to calculate the over all average speed grouped counts of vehicles traveled.

The format below shows that 5 vehicles traveled at 45km/h, 33 traveled at 55km/h, 65 at 65km/h etc.

What is the T-SQL to calculate the over all average speed of all the vehicles with the data set below? There can be up to 16 speed groups (eg 5, 15, 25, 35, 45 etc).

Count   Speed
5       45
33      55
65      65
25      75
2       85

Thanks in advance!

도움이 되었습니까?

해결책

I assume you are trying to get an overall average speed. If so, assuming T1 is the table name, your query should look like

select sum(count*speed)/sum(count) as overall_average from T1;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top