How should I calculate the average speed by road segment for multiple segments?
I have a table of driver speeds and road segments: driver_lpr | segment | speed 0000001 | A | 30 0000002 | B | 60 0000003 | A | 50 0000004 | A | 100 0000005 | B | 60 And I want to have a table of average speed per segment segment | average speed A | 47.368 B | 60 How can this be done in SQL ? Uri Goren When averaging speeds, the harmonic mean is in need. The straight forward AVG() approach is wrong, the arithmetic mean yields the wrong result for average velocity. There is no predefined function for the harmonic mean, but it could be achieved with this query: SELECT segment, COUNT(*)/SUM(1e0