LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

SQL Float Values : 255-3

Screen Link:

Views And Subqueries With SQL | Dataquest

My Code:

SELECT CAST(COUNT(*) as FLOAT) / (SELECT CAST (COUNT(*) as FLOAT FROM recent_grads) AS proportion_abv_avg 
  FROM recent_grads
  WHERE ShareWomen > (SELECT AVG(ShareWomen) FROM recent_grads);

The code ran perfectly.

My query is that DQ’s code below has " CAST & AS FLOAT" only in the numerator and not in the denominator. Shouldn’t that give an error , but it doesn’t. Why ?

SELECT CAST(COUNT() as FLOAT) / (SELECT COUNT() FROM recent_grads) AS proportion_abv_avg
FROM recent_grads
WHERE ShareWomen > (SELECT AVG(ShareWomen) FROM recent_grads);

Because a float divided by an integer or an integer divided by a float results in a float. So, there’s not really a need to cast both as float.