#4 Daily Revenue: What am I doing wrong?


#1

On #4: Daily Revenue, I am not sure what I am doing wrong or what I should do differently because it keeps saying "Sum the Daily Revenue"...here is my code that keeps getting the error:

SELECT date(ordered_at), ROUND(SUM(amount_paid), 2)
FROM orders
JOIN order_items
ON orders.id = order_items.order_id
GROUP BY 1
ORDER BY 1;

Please help!


#2

I meet the same situation like you.
But the code below can be accepted, I don't know why

select date(ordered_at), round(sum(amount_paid), 2)
from orders
join order_items on
orders.id =
order_items.order_id
group by 1
order by 1;


#3

I have the same problem. Code runs ok, but I can't go on


#4

Hello,

i had the same issue.
try copy paste the query from the instructions on the left and then replace /**/ by the correct code
it worked for me.

Cheers
Henri


#5

+1 - are we looking for the total daily revenue, or total revenue by day?
Thanks
Jasper


#6

I believe it wants the total revenue by day, since it asks "How much money has SpeedySpoon made from orders each day?: I also used the same code and got that error.


#7

+1 what exactly are we supposed to put ? and i don't understand the difference "total daily revenue" vs "total revenue by day" ?


#8

I had the same issue, I had the query working fine but it would not accept the code and I had to have it paste in it's own code before it would let me pass the exercise.


#9

Here is the code that worked for me which I got as help after being stuck for a long while.
select date(ordered_at), round(sum(amount_paid), 2)
from orders
join order_items on
orders.id = order_items.order_id
where name = 'kale-smoothie'
group by 1
order by 1;


#10

This code works for both 1 & 2 which has a where clause which makes it confusing for question 1 as it does not have the where clause. I tried this code and it worked for both questions.


#11

Code for #9 question 1 is
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
from order_items
order by id
limit 100;
and for question 2 is
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;


#13

thanks a lot ,I meet the same problem. then use your way ,I can move on.I think it's a bug in Codecademy


#14

select date(ordered_at), round(sum(amount_paid), 2)
from orders
join order_items on
orders.id = order_items.order_id
where name = 'kale-smoothie'
group by 1
order by 1;

That's the right code, which I had, but without the indentation on lines 3 and 4.
I did not realize that white space mattered, and although the indents show up in the text field where I pasted the code, they are lost when posted to the forum. Anybody else have this problem, try indenting line 3 2 space and line 4 4 spaces. I had to ask for the answer to figure this one out. (Don't like to do that!)


#15

It fails when I put sum in captials (SUM), try putting it all in lower case per the examples.


#16

I believe I found the culprit...

in the code where you enter round(sum(amount_paid), 2) you MUST add a space between the , and the 2 -- that makes the error go away and you can progress to the next step.

:smile: Mordy


#17

I ran the below query

select date(ordered_at), sum(amount_paid)
from orders join order_items on
orders.id = order_items.order_id
group by 1
order by 1;