首页 > 代码库 > mysql 自定义排序顺序

mysql 自定义排序顺序

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为排序字段,后面为该字段的相关值