使用case when 查询不同角色不同的内容

阅读更多

 

使用case  when 查询不同角色不同的内容

主要针对其他表,不同字段和角色比对,不是同一个字段和角色比对的简单情况

 

case when  可以放在任何地方

 

当然也可以用mybatise本身的标签:

 

复杂的sql都可借助网上资料查询结构,思路

 

 

 

   

     

     

        AND (CASE 

WHEN (SELECT ROLE_CODE FROM financial_sales_role WHERE ID = (SELECT ROLE_ID FROM financial_sales_user_role WHERE USER_ID = #{userId})) = 0 

THEN o.EMP_ID = (SELECT EMPID FROM financial_sales_user WHERE ID = #{userId})

WHEN (SELECT ROLE_CODE FROM financial_sales_role WHERE ID = (SELECT ROLE_ID FROM financial_sales_user_role WHERE USER_ID = #{userId})) = 1 

THEN o.TEM_ID = (SELECT TEMID FROM financial_sales_employment WHERE USER_ID = #{userId})

WHEN (SELECT ROLE_CODE FROM financial_sales_role WHERE ID = (SELECT ROLE_ID FROM financial_sales_user_role WHERE USER_ID = #{userId})) = 2 

THEN o.IMPORTER_ID = (SELECT EMPID FROM financial_sales_user WHERE ID = #{userId})

ELSE TRUE 

END)

     

     

        AND o.BATCH_NAME like CONCAT('%',#{batchName},'%' )

     

     

        AND o.CUSTOMER_ID=#{customerId}

     

     

        AND o.EMP_ID = #{empId}

     

        AND o.TEM_ID = #{temId}

     

 

     

        AND o.ORDERNO like CONCAT('%',#{orderno},'%' )

     

     

        AND o.CUSTOMER_NAME like CONCAT('%',#{customerName},'%' )

     

     

        and o.ASSIGN_TIME  >= #{prassignTime,jdbcType=VARCHAR}

     

     

        and o.ASSIGN_TIME <= #{lsassignTime,jdbcType=VARCHAR}

     

     

        and o.FIRSTDAIL_TIME  >= #{prfirstdailTime,jdbcType=VARCHAR}

     

     

        and o.FIRSTDAIL_TIME  <= #{lsfirstdailTime,jdbcType=VARCHAR}

     

     

        AND o.STATUS = #{status}

     

     

        and o.LASTDAIL_TIME  >= #{prlastdailTime,jdbcType=VARCHAR}

     

 

     

        and o.LASTDAIL_TIME >= #{lslastdailTime,jdbcType=VARCHAR}

     

     

        AND o.DIAL_RESULT = #{dialResult}

     

     

        AND o.DAIL_COUNT BETWEEN #{prdailCount} AND #{lsdailCount}

     

     

        AND o.ASSIGNSTATUS = #{assignStatus}

     

     

        AND o.IMPORTER_ID = #{importerId}

     

     

        AND o.ORDER_TYPE = #{orderType}

     

   

 

 

 

 

 

 

 

 

 

 

用于分页的sql:

 

PAGINATION:

 

 

 

 

 

     

 

 

     

               

           limit #{offset},#{pageSize}

     

 

 

 

 

 

 

你可能感兴趣的:(sql)