时间:2021-07-01 10:21:17 帮助过:4人阅读
结果查询不准确,当createUser没有在表1中创建数据时,查询结果为null,实际应该是表2数据有,但是结果中的resourceCatalogCount为0,经改正后的sql如下:
SELECT rcc.id, rcc.catalog_name, COUNT(DISTINCT rrc1.id) AS resourceCatalogCount,COUNT(DISTINCT rrm.id) AS resourceCount FROM (SELECT * FROM res_catalog_classify WHERE catalog_type = #{catalogType} AND parent_id != ‘0‘ AND is_publish = 1) rcc LEFT JOIN res_resource_classify rrc ON rcc.id = rrc.classify_id LEFT JOIN ( SELECT * FROM res_resource_catalog <where> <if test="createUser != null and createUser != ‘‘"> AND rrc1.create_user = #{createUser} </if> AND rrc1.is_publish = 1 </where> ) rrc1 ON rrc.resource_id = rrc1.id LEFT JOIN res_resource_mount rrm ON rrc.resource_id = rrm.resource_id GROUP BY rcc.id
mysql左连接查询结果不准确
标签:user null 相关 name join use group by sele distinct