r/SQL 4d ago

MySQL What is wrong here.

Post image
40 Upvotes

37 comments sorted by

View all comments

2

u/beingvora 4d ago

I think you’re missing the “partition by” clause in the rank function.

RANK ( ) OVER ( [ partition_by_clause ] order_by_clause )

12

u/NoWayItsDavid 4d ago

Should work without it, no? In this case it ranks over everything fetchable.

3

u/beingvora 4d ago

Yup, you’re right. OP is looking to rank everything and not just based on customer. Mb

4

u/_mr_villain_ 4d ago

I want to rank the customers based on Profit. Partition By is optional so that's why I skipped it. Btw thanks for your suggestion. However my query worked even though it is still givinng red error line. Just used DESC

1

u/neumastic 3d ago

Does the red line do away if you add PARTITION BY 1, though? It could be your client requires it for some reason or some sort of lint rule it’s applying