如果我有一张桌子......
ThingName | ThingCategory
-------------------------
thing 1 | cat1
thing 2 | cat2
thing 3 | cat3
Run Code Online (Sandbox Code Playgroud)
我将如何首先选择它们cat2,然后cat1呢cat3
这甚至可能吗?
select *
from Things
order by case
when ThingCategory = 'cat2' then 1
when ThingCategory = 'cat1' then 2
when ThingCategory = 'cat3' then 3
else 4 -- Might want the default case, too
end
Run Code Online (Sandbox Code Playgroud)