CYBER WEEK - EXTRA SAVINGS EVENT
TRY A FREE LESSON

How do u know if we have to change the column to FLOAT format? (R)

Screen Link:

Answer Key:

SELECT Major, Major_category, CAST(Sample_size as FLOAT)/Total AS ratio
FROM recent_grads
WHERE ratio > (SELECT AVG(CAST(Sample_size as FLOAT)/Total) AS avg_ratio
FROM recent_grads)

Question:
I would like to understand how do we know when to change the Sample_size column to Float? Is there a way to check that the column is not in numeric format & that we have to change to float?

Thank you!

1 Like

In Sqlite the division of an integer by another integer will always round down to the closest integer.

Therefore you should cast your numerator to a float.

to check the Datatypes of the columns use PRAGMA, it will display the table information:

PRAGMA table_info(recent_grads);
2 Likes