根据字段值来进行排序

将Role_Name为 Null 的列查询数据在前,来排序

ORDER BY
        (CASE
             WHEN r.role_name is null then 1
             WHEN r.role_name is not null then 2
         END)

完整SQL(自定义State列,是否分配权限,为空将值设为1未分配,否则就给2已分配)

<!--查询权限分配列表-->
<select id="getRoleAllot" parameterType="Map" resultType="HashMap">
select p.oid as "oid",p.user_code as "userCode",p.user_cname as "userCname",i.user_cname as "operatorName",
        u.operate_date as "operateDate",r.role_name as "roleName",
        (case when r.role_name is null then 1 else 2 end) as "state"
        from person_info p
        left join authority_user_role u on u.user_oid = p.oid
        left join authority_role r on r.oid = u.role_oid
        left join person_info i on u.operator = i.oid
        where  p.invalid_flag = '1'
        <if test="userCname != null and userCname != ''">
            and p.user_cname like '%${userCname}%'
        </if>
        <if test="roleName != null and roleName != ''">
            and r.role_name like '%${roleName}%'
        </if>
        <if test="allotFlag != null and allotFlag != ''">
            <if test="allotFlag == '1'.toString()">
                and r.role_name is null
            </if>
            <if test="allotFlag == '2'.toString()">
                and r.role_name is not null
            </if>
        </if>
        ORDER BY
        (CASE
             WHEN r.role_name is null then 1
             WHEN r.role_name is not null then 2
         END)
        <if test="pageNo != null and pageNo != ''">
            limit #{pageNo},#{pageSize}
        </if>
</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值