order by case when then end指定排序

实际数据

data             dataflag

aaa                    1

aaa                    2

aaa                    3

aaab                 3

dsab                 3

casscab          2

--------------------------------------

select * from testtable order by case when dataflag=2 then 0  when dataflag=1 then 1 when dataflag=3 then 2 end

--------------------------------------

casscab          2

aaa                   2

aaa                   1

aaa                   3

aaab                 3

dsab                 3

order by 对结果进行排序,case when then end用作于条件控制,二者混合使用就可以使结果指定顺序进行输出


猜你喜欢

转载自blog.csdn.net/kiranet/article/details/50369025