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

Monday, July 18, 2016

SQL: Table Transformation Lesson 18 Sample Solution


Instructions:
Find both the total flight distance as and flight distance by origin for Delta (carrier = 'DL').

Alias the flight distance as total_flight_distance and the and flight distance by origin as total_delta_flight_distance.

Sample Solution:
SELECT origin, sum(distance) as total_flight_distance, sum(CASE WHEN carrier = 'DL' THEN distance ELSE 0 END) as total_delta_flight_distance
FROM flights
GROUP BY origin;

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts