zoukankan      html  css  js  c++  java
  • 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为排序字段,后面为该字段的相关值

  • 相关阅读:
    NOI2019 I 君的商店
    CF1326F
    APIO2016 划艇
    LeetCode-Remove Nth Node From End of List
    LeetCode-Remove Element
    LeetCode-Remove Duplicates from Sorted List II
    LeetCode-Remove Duplicates from Sorted List
    LeetCode-Unique Paths II
    LeetCode-Unique Paths
    LeetCode-Remove Duplicates from Sorted Array II
  • 原文地址:https://www.cnblogs.com/mjorcen/p/3785516.html
Copyright © 2011-2022 走看看