zoukankan      html  css  js  c++  java
  • mysql的orde by 按照指定状态顺序排序

    要求按照以下顺序排序
    审核中->审核拒绝->待放款->放款失败->待还款->已结清->已逾期

    {
    id:80,
    label:'审核中'
    },{
    id:100,
    label:'审核拒绝'
    },{
    id:90,
    label:'待放款'
    },{
    id:170,
    label:'放款失败'
    }
    ,{
    id:175,
    label:'待还款'
    }
    ,{
    id:200,
    label:'已结清'
    }
    ,{
    id:180,
    label:'已逾期'
    }

    实现sql

      select
             id,
             phone,
             user_name AS userName,
             cid,
             product_id AS productId,
             product_name AS productName,
             status,
             repayment_status AS repaymentStatus,
             order_id AS orderId,
             associated_order_id AS associatedOrderId,
             apply_time AS applyTime,
             due_time AS dueTime,
             repayment_time AS repaymentTime,
             amount,
             product_amount AS productAmount,
             paid_amount AS paidAmount,
             actual_amount AS actualAmount,
             term,
             term_unit AS termUnit
            from
            loan_order
            <where>
                <if test="orderId != null and orderId !=''">
                    order_id = #{orderId}
                </if>
                <if test="associatedOrderId != null and associatedOrderId !=''">
                    and associated_order_id = #{associatedOrderId}
                </if>
                <if test="userName != null and userName !=''">
                    and user_name = #{userName}
                </if>
                <if test="status != null">
                    and status = #{status}
                </if>
                <if test="repaymentTime != null">
                    and repayment_status = #{repaymentTime}
                </if>
                <if test="phone != null and phone != ''">
                    and phone = #{phone}
                </if>
                <if test="cid != null and cid != ''">
                    and cid = #{cid}
                </if>
                <if test="productName != null and productName != ''">
                    and product_name = #{productName}
                </if>
                <if test="startApplyTime != null">
                    AND DATE_FORMAT(apply_time, '%Y-%m-%d') >= DATE_FORMAT(#{startApplyTime}, '%Y-%m-%d')
                </if>
                <if test="endApplyTime != null">
                    AND DATE_FORMAT(apply_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{endApplyTime}, '%Y-%m-%d')
                </if>
                <if test="startRepaymentTime != null">
                    AND DATE_FORMAT(repayment_time, '%Y-%m-%d') >= DATE_FORMAT(#{startRepaymentTime}, '%Y-%m-%d')
                </if>
                <if test="endRepaymentTime != null">
                    AND DATE_FORMAT(repayment_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{endRepaymentTime}, '%Y-%m-%d')
                </if>
            </where>
    
            order by (CASE
            WHEN `status` = 80  THEN 0
            WHEN `status` = 100 THEN 1
            WHEN `status` = 90  THEN 2
            WHEN `status` = 170 THEN 3
            WHEN `status` = 175 THEN 4
            WHEN `status` = 200 THEN 5
            WHEN `status` = 180 THEN 6
            ELSE 7 END) asc
  • 相关阅读:
    eclipse
    一次性验证码
    mybatis。逆向工程
    mybatis02.动态sql
    mybatis01
    plsql
    HDU.2149 Public Sale (博弈论 巴什博弈)
    HDU.1846 Brave Game (博弈论 巴什博弈)
    博弈论快速入门
    HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)
  • 原文地址:https://www.cnblogs.com/mlfz/p/10730318.html
Copyright © 2011-2022 走看看