How do brackets affect this code?


#1



I am wondering why THE BRACKETS change the result of the code. What is the order of operation there.?
I feel like I am missing something easy out. (first one is from "Get code" and second one is mine)



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

SELECT state, 100.0* (SUM(CASE WHEN elevation >=2000 THEN 1 ELSE 0 END)/ COUNT(id)) AS percentage_high_elevation_airports 
FROM airports  
GROUP BY 1;


#2

When dividing by an integer, I like to declare the numerator as a float, first, then divide. Was there any difference in the computed values for each one? If not, it might just be the SCT that expects the former and not the latter.


#3

Actually there was a difference in the results.


#6