我想首先获取特定位置的所有配置文件:
SELECT * FROM profile WHERE location IN ('a', 'b', 'c') OR isDefault=1 ORDER BY location IN ('a', 'b') DESC, -- put to the front if location in 'a','b' isDefault DESC, -- for each of both groups, put default profiles before the others. location ASC -- and sort each of the up to four groups by location.
这将引发错误:“关键字’IN’附近的语法不正确。”。如果删除了order子句,则返回结果。
这是怎么了
您可以重写该值以返回可排序的整数:
case when location IN ('a', 'b') then 0 else 1 end DESC