Grouping with Case Statements Step 2 - Can't Get This to Pass

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
Hi, I’ve been stuck on this exercise for over an hour and I can’t seem to find any help. Usually, after several attempts it will give me the solution but not in this case. Anyone spot what I did wrong?

https://www.codecademy.com/en/courses/sql-analyzing-business-metrics/lessons/advanced-aggregates/exercises/product-grouping?action=resume

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Error: near line 1: near “select”: syntax error
<In this course, it often helps to include a screenshot of your whole web browser – that lets everyone see what you see. If you wish to include a screenshot, add it below this line.>

<If you wish to copy/paste in your code, you can use this next section. This will allow others to copy/paste your code for testing – something that they won’t be able to do with just a screenshot.>

```

SELECT *,
CASE name
WHEN ‘kale-smoothie’ THEN ‘smoothie’
WHEN ‘banana-smoothie’ THEN ‘smoothie’
WHEN ‘orange-juice’ THEN ‘drink’
WHEN ‘soda’ THEN ‘drink’
WHEN ‘blt’ THEN ‘sandwich’
WHEN ‘grilled-cheese’ THEN ‘sandwich’
WHEN ‘tikka-masala’ THEN ‘dinner’
WHEN ‘chicken-parm’ THEN ‘dinner’
ELSE ‘other’
END
AS category,
round(1.0 * sum(amount_paid) /
sum(select amount_paid from order_items) * 100, 2)
AS pct
FROM order_items
GROUP BY 1
ORDER BY 2 desc;

<do not remove the three backticks above>

@johnnybass99 I’m getting the same error message.

Here’s what I have - appreciate any help!

select *,
case name
    when 'kale-smoothie'    then 'smoothie'
    when 'banana-smoothie'  then 'smoothie'
    when 'orange-juice'     then 'drink'
    when 'soda'             then 'drink'
    when 'blt'              then 'sandwich'
    when 'grilled-cheese'   then 'sandwich'
    when 'tikka-masala'     then 'dinner'
    when 'chicken-parm'     then 'dinner'
     else 'other'
  end as category, round (1.0 * sum(amount_paid) / 
         (select sum(amount_paid) from order_items * 100, 2)) as pct
from order_items
group by 1
order by 2 desc; 

Finally got it!!!

select
  case name
    when 'kale-smoothie'    then 'smoothie'
    when 'banana-smoothie'  then 'smoothie'
    when 'orange-juice'     then 'drink'
    when 'soda'             then 'drink'
    when 'blt'              then 'sandwich'
    when 'grilled-cheese'   then 'sandwich'
    when 'tikka-masala'     then 'dinner'
    when 'chicken-parm'     then 'dinner'
    else 'other'
  end as category, round(1.0 * sum(amount_paid) /
    (select sum(amount_paid) from order_items) * 100, 2) as pct
from order_items
group by 1
order by 2 desc;

Oh yeah!! Thanks much that works for me too.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.