DavidSzczesniak
1/25/2018 - 10:27 AM

Combining Aggregates

This can be used to create precentages or ratios.

\!h Example - percentage of flight distance that is from Delta, by origin:
SELECT     origin, 
    100.0*(sum(CASE WHEN carrier = 'DL' THEN 
distance ELSE 0 END)/sum(distance)) as
percentage_flight_distance_from_delta FROM flights 
GROUP BY origin;