订购......在(...)ASC

Ale*_*der 5 sql sql-server

我希望首先获得特定位置的所有配置文件:

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.
Run Code Online (Sandbox Code Playgroud)

这会引发错误:"关键字'IN'附近的语法不正确." 如果我删除了order子句,则返回结果.

这有什么不对?

Pat*_*man 11

您可以重写它以返回可以排序的整数:

case when location IN ('a', 'b') then 0 else 1 end DESC
Run Code Online (Sandbox Code Playgroud)