原创

MySQL-代码-从明细表中提取主数据信息

<!--从明细表中提取主数据信息 and a.type = 1 GROUP BY a.enterprise_id,a.type,a.id -->
<select id="getList" resultType="com.safety51.eduinp.pojo.vo.enterprise.CommentVo">
SELECT a.enterprise_id enterpriseId, b.enterprise_name enterpriseName,
a.comment_name commentName,a.attachment_id attachmentId,
a.comment_main_id commentMainId
FROM eduinp_comment a
INNER join eduinp_enterprise b on a.container_id = b.container_id and a.enterprise_id = b.id
WHERE a.container_id = #{containerId}
<if test="enterpriseName != null and enterpriseName != ''">
and b.enterprise_name like CONCAT('%', #{enterpriseName}, '%')
</if>
and a.is_delete = 0 and b.is_delete = 0
<!-- GROUP BY a.comment_main_id order by a.id desc 如果使用这个还要改造按comment_main_id分组,取最小id值 -->
and a.type = 1 GROUP BY a.enterprise_id, a.type,a.id order by a.id desc
<!-- and a.type = 1 GROUP BY a.enterprise_id,a.type,a.id order by a.id desc 如果只按这个,
那如果取某个评价明细,就因为明细间没有关联关系,而会带出其他评价下的明细 -->
</select>

说明:这里的comment_main_id 作为主表id ,也可用于明细间的关联关系

正文到此结束
本文目录