ORDER BY

多表查询造成重复字段进行排序造成错误,可以对数据进行封装,把字段唯一化,再进行排序

select * from (
     select
t1.*, t2.REQ_CLASS_ID, t2.REQ_TYPE_NAME, t3.REQ_CLASS_NAME,
submitter.user_name as SUBMIT_USER_NAME,
cmo.user_name as CMO_NAME,
t4.user_name as MODIFY_USER_NAME,
dic_reqLevel.Dictionary_Name as REQ_LEVEL_NAME,
dic_reqStatus.Dictionary_Name as REQ_STATUS_NAME
    from SRM.REQ_REQUIREMENTINFO t1
    left join SRM.REQ_REQUIREMENTTYPE t2
    on t1.REQ_TYPE_ID = t2.ID
    left join SRM.REQ_REQUIREMENTCLASS t3
    on t2.REQ_CLASS_ID = t3.ID
    left join BSP.SYS_USERINFO submitter
    on t1.user_id = submitter.id
    left join BSP.SYS_USERINFO cmo
        on t1.cmo = cmo.id
    left join BSP.SYS_USERINFO t4
        on t1.MODIFY_USER = t4.id
    left join (select * from sys_dictionary dic where dic.dictionary_type_id = 6) dic_reqLevel
        on t1.REQ_LEVEL = dic_reqLevel.Dictionary_Code
    left join (select * from sys_dictionary dic where dic.dictionary_type_id = 5) dic_reqStatus
        on t1.REQ_STATUS = dic_reqStatus.Dictionary_Code
    <![CDATA[ where 1=1 ]]>
    <if test="reqName != null and reqName != ''">
and REQ_NAME like concat(concat('%',#{reqName, jdbcType=VARCHAR}),'%')
</if>
<if test="reqLevel != null and reqLevel != ''">
and REQ_LEVEL like concat(concat('%',#{reqLevel, jdbcType=VARCHAR}),'%')
</if>
<if test="reqStatus != null and reqStatus != ''">
and REQ_STATUS like concat(concat('%',#{reqStatus, jdbcType=VARCHAR}),'%')
</if>
<if test="reqClassId != null and reqClassId != ''">
and REQ_CLASS_ID = #{reqClassId, jdbcType=DECIMAL}
</if>
<if test="reqTypeId != null and reqTypeId != ''">
and REQ_TYPE_ID = #{reqTypeId, jdbcType=DECIMAL}
</if>
<if test="userId != null and userId != ''">
and USER_ID = #{userId, jdbcType=DECIMAL}
</if>
<if test="cmo != null and cmo != ''">
and CMO = #{cmo, jdbcType=DECIMAL}
</if>
<if test="startTime != null and startTime != '' ">
and REQ_TIME >= to_date(#{startTime, jdbcType=VARCHAR},'yyyy-MM-dd / hh24:mi:ss')
</if>
<if test="endTime != null and endTime != '' ">
and REQ_TIME  <![CDATA[<=]]> to_date(#{endTime, jdbcType=VARCHAR},'yyyy-MM-dd / hh24:mi:ss')
</if>
)
<if test="sortColumns != null and sortColumns !='' ">
ORDER BY ${sortColumns}
</if>

猜你喜欢

转载自lixgjob.iteye.com/blog/2280309
今日推荐