I have the following sorting problem in SQL.
SELECT time, orderValue
FROM orders
ORDER BY time
The issue is that time is expressed by a string in the following format:
May 2012
June 2012
...
June 2013
The ORDER BY clause however sorts the problem in an alphabetic order (which is not strange since it's defined as a string). How to sort this in a correct order based on year and month?
Try:
SELECT time, orderValue
FROM orders
ORDER BY CONVERT (DATETIME, '01 ' + time, 104)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With