BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Inequality Question

Hello,
I had a question in the “Group Summary Stats” Mission on Page 2.

URL: Learn data science with Python and R projects

SELECT 
	CASE
    WHEN Sample_size < 200 THEN "Small"
    WHEN 200 >= Sample_size < 1000 THEN "Medium"
    WHEN Sample_size >= 1000 THEN "Large"
    END AS Sample_category
	FROM recent_grads;

I believe the issue is with the 2nd WHEN condition. How would you write this (correctly) as an inequality?

You’ll have to break this WHEN clause and use the AND operator.

WHEN Sample_size >= 200 AND Sample_size < 1000 THEN 'Medium'

Also, add an ELSE clause. I guess, here we must use it for answer checking purposes.

But in general, we do not need an ELSE clause. If one isn’t specified, ELSE will return NULL. In other words, it acts as though it has an ELSE NULL clause.

1 Like

Hi @dash.debasmita,

I tried what you did and it worked. However, I have a new (but related question). In a previous mission there was this:

"Note that we use code like 10000000 < data_size <= 50000000 — this is equivalent to 10000000 < data_size and data_size <= 50000000"

So, I tried 200<=Sample_size<1000 and it didn’t work. I don’t know why. I thought that and what you wrote would be equivalent.

Also, I did end with and END AS clause. Did I do something wrong?.

It won’t work in SQL. You can break that condition with the AND operator or can use the BETWEEN operator.

Sorry for the typo. I meant to say, use the ELSE clause. I have edited my post, please read it again.
Hope it makes sense now.

Hi @dash.debasmita,
Thank you for the info! I didn’t know setting up inequalities like that would be an issue in SQL. No worries about the typo…I’ve made my fair share :grin:

1 Like