根據主表某字段不一樣 關聯不一樣的表

<select id="selectAllByType" parameterType="com.acp.dto.AcpUserDto" resultMap="UserApiMap">
select
d.id,d.username,d.user_type,c.name ,c.email,c.mobile
,c.unified_credit_id,d.last_login_ip,d.last_login_time,f.name
as rolename,c.id as infoId
from acp_user d
left join acp_user_developer
c on c.user_id=d.id
left join acp_user_role e on d.id=e.user_id
left join acp_role f on f.id=e.role_id
<trim prefix=" WHERE " prefixOverrides="AND">
d.user_type = 5 and d.del=1
<if test="id != 0"> AND d.id = #{id} </if>
<if test="username != null"> AND username like '%${username}%'</if>
<if test="userType != 0"> AND user_type = #{userType} </if>
</trim>ide

union all
  select
  d.id,d.username,d.user_type,b.`name` ,b.email,b.mobile ,b.unified_credit_id
  ,d.last_login_ip,d.last_login_time,f.`name` as rolename,b.id as infoId
  from acp_user d
  left join acp_user_agent b on b.user_id=d.id
  left join acp_user_role e on d.id=e.user_id
  left join acp_role f
  on f.id=e.role_id
  &lt;trim prefix=" WHERE " prefixOverrides="AND"&gt;
      d.user_type = 4 and d.del=1
      &lt;if test="id != 0"&gt; AND d.id = #{id} &lt;/if&gt;
      &lt;if test="username != null"&gt; AND username like '%${username}%' &lt;/if&gt;
      &lt;if test="userType != 0"&gt; AND user_type = #{userType} &lt;/if&gt;
  &lt;/trim&gt;
  union all
  select
  d.id,d.username,d.user_type,a.`name`,a.email
  ,a.mobile ,null ,d.last_login_ip,d.last_login_time
  ,f.`name` as rolename,a.id as infoId
  from acp_user d
  left join acp_user_reviewer a on a.user_id=d.id
  left join acp_user_role e on
  d.id=e.user_id
  left join acp_role f on
  f.id=e.role_id
  &lt;trim prefix=" WHERE " prefixOverrides="AND"&gt;
      d.user_type = 3 and d.del=1
      &lt;if test="id != 0"&gt; AND d.id = #{id} &lt;/if&gt;
      &lt;if test="username != null"&gt; AND username like '%${username}%'&lt;/if&gt;
      &lt;if test="userType != 0"&gt; AND user_type = #{userType} &lt;/if&gt;
  &lt;/trim&gt;

</select>code

相關文章
相關標籤/搜索