专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > DB2

数据排序有关问题(描述清楚有点复杂,具体请看里面的内容)

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
数据排序问题(描述清楚有点复杂,具体请看里面的内容)
比如我有一个表,有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
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: