有没有办法在MySQL中通过Word订购?
例如:
SELECT * FROM `table` WHERE `batch` = 'something' AND outcome in ('Business','Professional', 'Consumer')
我想按顺序获取行列表:Business,Professional,然后是Consumer而不是字母顺序。
答案 0 :(得分:1)
试试这个:
SELECT *
FROM `table`
WHERE `batch` = 'something'
AND outcome in ('Business','Professional', 'Consumer')
ORDER BY
CASE WHEN outcome = 'Business' THEN 1
WHEN outcome = 'Professional' THEN 2
WHEN outcome = 'Consumer' THEN 3
ELSE 4
END
答案 1 :(得分:0)
你可以专门联合每一个......试试这个。
SELECT * FROM `table` WHERE `batch` = 'something' AND outcome = 'Business'
UNION
SELECT * FROM `table` WHERE `batch` = 'something' AND outcome = 'Professional'
UNION
SELECT * FROM `table` WHERE `batch` = 'something' AND outcome = 'Consumer'