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

mysql 自定义排序顺序

时间:2014-06-15 21:32:00      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   ext   color   

mysql 自定义排序顺序 

实例如:在sql语句中加入ORDER BY FIELD(status,3,4,0,2,1)语句可定义排序顺序 

 

SELECT tsdvoucher0_.VOUCHER_ID AS VOUCHER1_0_, tsdvoucher0_.COMMENT_DEVICE_TYPE AS COMMENT2_0_, tsdvoucher0_.COMMENT_ID AS COMMENT3_0_, tsdvoucher0_.COMMENT_PERSON_NO AS COMMENT4_0_, tsdvoucher0_.COMMENT_PIC AS COMMENT5_0_
    , tsdvoucher0_.COMMENT_SPENDING AS COMMENT6_0_, tsdvoucher0_.CREATE_TIME AS CREATE7_0_, tsdvoucher0_.RESTAURANT_CONTEXT AS RESTAURANT8_0_, tsdvoucher0_.RESTAURANT_ID AS RESTAURANT9_0_, tsdvoucher0_.RESTAURANT_NAME AS RESTAURANT10_0_
    , tsdvoucher0_.USER_ID AS USER11_0_, tsdvoucher0_.VERSION AS VERSION0_, tsdvoucher0_.VOUCHER_ACT_ID AS VOUCHER13_0_, tsdvoucher0_.VOUCHER_ACT_RATIOS AS VOUCHER14_0_, tsdvoucher0_.VOUCHER_BUSINESS_STATUS AS VOUCHER15_0_
    , tsdvoucher0_.VOUCHER_CHECK_STATUS AS VOUCHER16_0_, tsdvoucher0_.VOUCHER_CHECKED_TIME AS VOUCHER17_0_, tsdvoucher0_.VOUCHER_DENOMINATION AS VOUCHER18_0_, tsdvoucher0_.VOUCHER_PIC AS VOUCHER19_0_, tsdvoucher0_.VOUCHER_USED_TIME AS VOUCHER20_0_
    , tsdvoucher0_.VOUCHER_VALID_DAY AS VOUCHER21_0_
FROM T_SD_VOUCHER tsdvoucher0_
WHERE tsdvoucher0_.USER_ID = ?
ORDER BY FIELD(tsdvoucher0_.VOUCHER_BUSINESS_STATUS, 3, 4, 6, 5), FIELD(tsdvoucher0_.VOUCHER_CHECK_STATUS, 3, 2, 4), tsdvoucher0_.CREATE_TIME ASC

 

 

 


说明:status为排序字段,后面为该字段的相关值

mysql 自定义排序顺序,布布扣,bubuko.com

mysql 自定义排序顺序

标签:style   class   blog   code   ext   color   

原文地址:http://www.cnblogs.com/mjorcen/p/3785516.html

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