Sometimes I give parts of a solution to increase the play time to
solve a problem. I didn’t anticipate a problem when showing how
to perform a sort operation with a CASE statement.
It’s a sweet solution when you need to sort something differently
than a traditional ascending or descending sort.
I gave my students this ORDER BY clause as an
example:
CASE
WHEN filter = 'Debit' THEN 1
WHEN filter = 'Credit' THEN 2
WHEN filter = 'Total' THEN 3
END;
|
It raises the following error in MySQL for students:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY
CASE
WHEN filter = 'Debit' THEN 1
WHEN filter = 'Credit' THEN' at line 6
|
It raises the …
[Read more]