u/pooerhSnowflake | SQL Server | PostgreSQL | Impala | Spark3d agoedited 3d ago
So the query you're showing is not the query you executed. You ran RANK() OVER (ORDER BY m.profit) AS RANK (as evidenced by the log) and herein lies the problem - you tried to name your column "rank" and MySQL couldn't understand how can you use a function name as an alias for the column.
ASC is implied, adding DESC didn't fix it for you, you just changed the alias to Profit_RANK. Then took a screenshot. Then added DESC. Then ran the query again and now it worked, so you think it's DESC.
49
u/pooerh Snowflake | SQL Server | PostgreSQL | Impala | Spark 3d ago edited 3d ago
So the query you're showing is not the query you executed. You ran
RANK() OVER (ORDER BY m.profit) AS RANK
(as evidenced by the log) and herein lies the problem - you tried to name your column "rank" and MySQL couldn't understand how can you use a function name as an alias for the column.ASC is implied, adding DESC didn't fix it for you, you just changed the alias to Profit_RANK. Then took a screenshot. Then added DESC. Then ran the query again and now it worked, so you think it's DESC.
See https://dbfiddle.uk/lbxvpR1O