mysql count 统计 值为0 时 不显示问题

select IFNULL(total,0) as num, bs.name as name, bs.id
from bdc_standard bs
left join (select dx_type,count(*) as total from obe_construct_project GROUP BY dx_type) as ocp
on bs.id = ocp.dx_type
where bs.parent_id = (select id from bdc_standard where code ='XMGNYTFL' )

ifnull(目标,替换值) ;; 目标值如果为 null, 则替换为替换值

先进行 count 统计, 然后再 联查替换, 将 count为null的 替换为 0

你可能感兴趣的:(mysql,mysql)