我有以下SQL:
SELECT *
FROM forum_l.entries
WHERE bindningstid = 1
ORDER BY
CASE
WHEN rabatt IS NULL THEN 1
ELSE 0
END, rabatt DESC,
CASE
WHEN paslag IS NULL THEN 1
ELSE 0
END, paslag ASC
所以我首先得到一个值(rabatt),我想订购desc,然后我想订购字段paslag Asc但仍然保持null。
答案 0 :(得分:2)
你应该替换案件:
SELECT *
FROM forum_l.entries
WHERE bindningstid = 1
ORDER BY
CASE
WHEN rabatt IS NULL THEN 0
ELSE 1
END, rabatt DESC,
CASE
WHEN paslag IS NULL THEN 0
ELSE 1
END, paslag ASC