9.2 What is wrong here?


#1

select *,
case (order_items.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 amount_paid from order_items) * 100, 2) as pct
from order_items
group by category
order by 2 desc
limit 100;

I get a "group by category" error message.


#2

Please post a link to this lesson. Thank you.


#3

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


#4

I think this is a dupe of http://discuss.codecademy.com/t/grouping-with-case-statement-part-2-maybe-a-mistake/17497

first line also selects all when you just need to select by the created category


#5

select
  case name

Is this what you mean to correct?


#6
select
  case name

Yes that's exactly it, I ran into the same thing and it took me a while to figure it out.


#7

I am getting the error -
Error: near line 1: near ";": syntax error Error: near line 14: near "(": syntax error
My code is following. Where is the mistake? I cannot figure out.
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;


#8

I duplicated the spacing and indentation from the exercise and with the same code and syntax it worked. I passed the course. :smile:


#9

No telling what the issue might have been. I tested your code (with no indents) and it passed.