多表联查进行数据统计时,建议使用子查询,否则统计的数据不准确
<select id="selectLnCensusArticleList" parameterType="LnArticle" resultMap="LnArticleResult">
SELECT
(select count(lc.collection_id) from ln_collection lc where lc.collection_id = la.id and lc.type = 'article') collectionCount,
(select count(lac.article_id) from ln_article_comment lac where lac.article_id = la.id) commentCount,
(select count(lsl.support_id) from ln_support_log lsl where lsl.support_id = la.id and lsl.type = 'article') supportCount,
(select count( lab.browse_id) from ln_browse lab where lab.browse_id = la.id and lab.type = 'article') browseCount,
(select count(lar.reward_id) from ln_article_reward lar where lar.reward_id = la.id ) rewardCount,
la.*
FROM
ln_article la
<where>
<if test="title != null and title != ''"> and la.title like concat('%', #{title}, '%')</if>
</where>
</select>