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


#1


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


Error: near line 1: near "select": syntax error



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;


#2

@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;

#3

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;

#4

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


#5

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