答案 0 :(得分:6)
当ORDER BY -1 * SecondField
为偶数时,您可以FirstField
。
SELECT *
FROM tbl
ORDER BY
FirstField,
CASE
WHEN FirstField % 2 = 0 THEN -1 * SecondField
ELSE SecondField
END
答案 1 :(得分:0)
您可以使用三个排序,并保持未使用的顺序不变:
select *
from myTable
order by FirstField,
case when FirstField % 2 = 0 then SecondField else 0 end desc,
case when FirstField % 2 = 1 then SecondField else 0 end asc