SQL: TABLE TRANSFORMATIONS (6. COMBINING AGGREGATES)
I have been working on my code and could see that the return values are always 0 and 100, hence tried rounding up my values and could see that they are returning the required percentages. However, I wanted to check whether I am on the right track?
SELECT origin, SUM(distance) AS total_distance, SUM(CASE WHEN carrier = 'DL' THEN distance ELSE 0 END) AS total_DL_distance, ROUND(100.0*SUM(CASE WHEN carrier = 'DL' THEN distance ELSE 0 END)/SUM(DISTANCE)) AS Percent_DL_Distance FROM flights GROUP BY origin;
Kindly confirm if this is correct. THANK YOU IN ADVANCE