首先构建好思路,写两条sql
我的表结构父类为0,子类的pid为父类的id
<!--第一次查询,完整目录列表 + 二级目录试题数
List<ResourceStandardVO> selectAllResources();-->
<select id="selectAllResources" resultMap="StandardResultMap">
select if(r.main_cat = 0, r.id, r.main_cat) as pid,
r.id,
r.word_count,
r.code,
r.main_cat,
r.title,
r.cover,
r.difficulty,
r.updated_at,
count(q.id) as question_count
from resources r
left join questions q on r.id = q.cat_id
group by pid, r.id, r.sort
order by pid, r.sort
</select>
<!-- //第二次查询,一级目录的试题数+单词数
List<FrontResourceEntity> selectAllTwo(Long ids);
-->
<select id="selectAllTwo" resultMap="Resour