码迷,mamicode.com
首页 > 数据库 > 详细

[SQL] 让特定的数据 排在最前

时间:2016-09-06 17:00:34      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

MYSQL目前常用的两种方法,如下:

 

让值为"张三" 的数据排在最前.

-- 方法一
select * from tableName  ORDER BY  case when columnName=‘张三‘ then 0  else 1 end  asc


-- 方法二
select * from tableName  where columnName =‘张三‘ union all select * from tableName  where columnName <>‘张三‘

 

[SQL] 让特定的数据 排在最前

标签:

原文地址:http://www.cnblogs.com/justang/p/5846328.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!