比如我有一个表,有a,b,c三列
a b c
1 aa 99
2 dd 80
3 fg 98
4 fk 95
现在我select整个表后,要按照b列的值=fk的排在第一,值=fg的排在第二,剩下的order by b排序,这样的SQL语句应该怎么写??
------解决方案--------------------
order by case b when 'fk' then 1 when 'fg' then 2 else 3 end
------解决方案--------------------
order by case b when 'fk' then 1 when 'fg' then 2 else 3 end
--这个是按照你说的b进行排序的,如果在按照c和a排序
加上c,a
如果fk有多个的话,排序是不确定的,你可以在加上你想要的排序字段
order by case b when 'fk' then 1 when 'fg' then 2 else 3 end ,c,a...
------解决方案--------------------
order by case b when 'fk' then 1 when 'fb' then 2 else null end,c,a