Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, July 18, 2016

SQL: Table Transformation Lesson 19 Sample Solution


Instructions:
Find the percentage of flights from Delta by origin (carrier = 'DL')

In the query, alias the column as
percentage_flight_distance_from_delta

Sample Solution:
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;

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts