同表、同字段、3段查询
SELECT
c2.TName TName1,
c1.TName TName2,
p_d_country.TName TName3,
COUNT (tb_z_entbase.Enba_qid) Enba_qid,
COUNT (tb_z_project.Proj_id) Proj_id
FROM
p_d_country
LEFT JOIN tb_z_project ON p_d_country.TID = tb_z_project.Proj_country
LEFT JOIN p_d_country c1 ON c1.TID = p_d_country.UpperID
AND c1.UpperID != '0'
LEFT JOIN p_d_country c2 ON c2.TID = c1.UpperID
AND c2.UpperID = '0'
LEFT JOIN tb_z_entbase ON tb_z_entbase.Enba_qid = tb_z_project.Pro_id
WHERE
c1.TName != 'null'
GROUP BY
p_d_country.TName,
c1.TName,
c2.TName