<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper">
    <select id="queryCommentCount" resultType="java.lang.Integer">
        select d.commentCount + d.replyCount
        from (select c.article_id,
                     count(1)                            as commentCount,
                     (select count(1) as replyCount
                      from community_article_comment a
                               left join community_comment_reply b on a.id = b.comment_id
                      where a.article_id = #{articleId}) as replyCount
              from community_article_comment c
              where c.article_id = #{articleId}) as d
    </select>
</mapper>