Combining Aggregates Brackets


#1


https://www.codecademy.com/courses/sql-table-transformation/lessons/conditional-aggregates/exercises/combining-aggregates-i?action=lesson_resume&link_content_target=interstitial_lesson

https://www.codecademy.com/en/courses/sql-table-transformation/lessons/conditional-aggregates/exercises/combining-aggregates-ii


I wonder why I don't need another bracket in the second select statement after the 100.0 * as in the first select statement it is correct to use a bracket.


SELECT  origin, 
100.0*(sum(CASE WHEN carrier = 'UN' THEN distance ELSE 0 END)/sum(distance)) as percentage_flight_distance_from_united FROM flights 
GROUP BY origin;

SELECT state, 100.0 * sum(CASE WHEN elevation >= 2000 THEN 1 ELSE 0 END) / count(*) as percentage_high_elevation_airports FROM airports GROUP BY state;


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.