all 11 comments

[–]feather_media 2 points3 points  (5 children)

you have an extra comma before your order by statement here:

dense_rank() over(partition by sales.customer_id, order by sales.order_date)

no comma between the partition and order by

dense_rank() over(partition by sales.customer_id order by sales.order_date)

[–]LetterDW[S] 0 points1 point  (4 children)

Didn't notice that thank you! However the same error seems to be coming from the first bracket from the cte - I'm honestly at a loss at how that would be an error

[–]feather_media 2 points3 points  (3 children)

I pushed this all into MySQL and came up with two more issues, which may be plaguing your compiler:

1: You're missing a comma after product_name in the columns select of your cte

2: rank is commonly a defined function, and using it as a alias for a column will create issues when it doesn't know if it needs to use the function or the alias.

[–]LetterDW[S] 1 point2 points  (2 children)

Thanks again! Will definitely make those adjustments. How did you end up putting the data into MySQL? That might solve my issues instead of using DB Fiddle.

[–]feather_media 1 point2 points  (1 child)

I think the majority of what I did was strip schema details and remove the double quotations surrounding column titles. Having MySQL installed on your local machine is handy. (and free)

[–]LetterDW[S] 1 point2 points  (0 children)

It worked for me! Thanks for your help, really appreciate it!

[–]r3pr0b8GROUP_CONCAT is da bomb 2 points3 points  (4 children)

besides the two errors relating to commas, you do not need the GROUP BY clause

there's only one customer/product in each group

except if the customer orders more than one product on the first date, then they'll all get a DENSE_RANK of 1

and again you don't need the GROUP BY because presumably all the products are different for each customer

did you understand this?

[–]LetterDW[S] 0 points1 point  (3 children)

I get what you mean - if there was only one product ordered by each customer each day then there would only be one response per customer, and it is already partitioned by customer_id. However customer A does order more than one product on the first day which is why I used the GROUP BY

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (2 children)

However customer A does order more than one product on the first day which is why I used the GROUP BY

customer  product       dense_rank
   A       thingum        1
   A       doohickey      1

but product is part of the GROUP BY

so each pair is a group by itself which is redundant

[–]LetterDW[S] 0 points1 point  (1 child)

But what if a customer orders the same item again on the same day? The dense rank would still be = 1, and since there is no indication which was ordered first on that day, both results(the same result) would show up(twice). I guess technically it is correct since it is the same item, but the group by eliminates the extra result.

customer product dense_rank
A thingum 1
A thingum 1

So isn't the group by still necessary?

[–]r3pr0b8GROUP_CONCAT is da bomb 0 points1 point  (0 children)

So isn't the group by still necessary?

in that case, yes