Reputation: 6319
suppose I have a table which has a column days('mon','tue','wed','thu','fri'), how do I implement a days-of-week order (rather than lexicographical order) to them?
eg.
'mon'<'tue' //produce true
'fri'>'wed' //true
'fri'<'thu' //false
Thanks in advance!
Upvotes: 0
Views: 254
Reputation: 146540
Not the way you want:
ORDER BY CASE day
WHEN 'mon' THEN 1
WHEN 'tue' THEN 2
...
WHEN 'sun' THEN 7
END
Edit: you can also create a second table:
day_name day_order
======== =========
mon 1
tue 2
...
sun 7
... and JOIN and SORT when SELECTing.
Last but not least, store days as numbers :)
Upvotes: 2