BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Missing content from lesson

Screen Link:
https://app.dataquest.io/m/592/control-flow/2/if-then-in-sql

This page is missing reference to the “AS” function that comes after ‘END’. The dummy code provided is missing this:

SELECT some_columns,
   (CASE
      WHEN [condition] THEN [value]
      ELSE [another_value]
   END)

FROM some_table;

To this:

SELECT some_columns,
       (CASE
          WHEN [condition] THEN [value]
          ELSE [another_value]
       END) AS new_column
  FROM some_table;

AS should also be mentioned in the paragraph following.
It took me a minute to realize and could only make out the tiny text from the included screenshot in the lesson.

Hi @yee.laurene:

Please raise a ticket via Contact Us > Send in a ticket at the top right corner beside the magnifying glass icon, to let the content team know about this. Thanks!

Hey, Lauren.

This is a genuine question: in what sense is it missing?

I don’t think it is missing AS, as AS isn’t necessary for CASE ... END to work.

Hey Bruno,
It’s missing from the course content example I quoted above. The answer required to go to the next page requires the “AS” in order for you to move on to the next lesson. I think it would be helpful to add a line like:

AS will create a new column filled with the values from your case definition

Hi @yee.laurene. The reason for this is that the exercise requires the column to be named total_category in order for it to be accepted by the system. Omitting AS will cause the column to be named (CASE WHEN total > 10 THEN 'High' ELSE 'Low' END) but it will still create the new column with the expected data.

Technically speaking, this is not entirely true because AS is used for aliasing a column name…it does not actually create the column itself. It is the CASE statement that actually creates a new column. Perhaps your suggestion could be reworded as:

AS will create an alias for a new column filled with the values from your case definition

That said, I agree with you that for completeness sake, the example would be more complete if it were changed to something like

SELECT some_columns,
       (CASE
          WHEN [condition] THEN [value]
          ELSE [another_value]
       END) AS [alias_for_case_column]
  FROM some_table;

We have the following match between the queries:

some_table: customer
some_columns: customer_id, first_name, last_name, country
[value]: 'Europe'
[another_value]: 'Not Europe'
[alias_for_case_column]: continent
[condition]:

sql WHEN country IN ('Austria','Belgium', 'Czech Republic', 'Denmark', 'Finland', 'France', 'Germany', 'Hungary', 'Ireland', 'Italy', 'Netherlands', 'Norway', 'Poland', 'Portugal', 'Spain', 'Sweden', 'United Kingdom' )

While building this answer, I also see there is a typo (I believe) in the above block of text: sql WHEN country IN... I don’t believe sql should be part of the WHEN statement and is just adding to confusion.

Have you submitted a ticket as @masterryan.prof suggested? I think that’s the best way to have your concerns addressed for this screen.

1 Like

Thanks for spotting the typo, Mike. I fixed it.

As for AS, I’m not convinced it is helpful to include it. The focus is on the CASE expression and I want to keep surrounding context at a minimum.

1 Like