我有以下SELECT
声明:
SELECT `facility_name`, `day`, `month`, `year`, `start_time`, `end_time`
FROM reservation_db
WHERE user_id = '$userID'
ORDER BY `facility_name` ASC, `year` ASC, `day` ASC, `start_time` ASC, `end_time` ASC"
它工作正常,但在我的表中我还有一个列month
,其中包含字符串的月份(即“Ian”,“Feb”,“Mar”等) 。更改存储在列中的数据类型现在不再是一个选项..如何使用ORDER BY
对它们进行排序?
答案 0 :(得分:2)
在您的订单中添加case
表达式,每月返回的数字为:
order by case `month` when 'Jan' then 1
when 'Feb' then 2
when 'Mar' then 3
...
when 'Dec' then 12
end