首页 > 代码库 > 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为排序字段,后面为该字段的相关值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。