SELECT d.*,COUNT(c.id) cCount FROM (SELECT a.*,COUNT(b.id) bCount FROM guang a LEFT JOIN guang2 b ON a.id = b.pid GROUP BY a.id ) AS d LEFT JOIN guang3 c ON d.id = c.fid GROUP BY d.id ORDER BY d.bCount DESC,cCount DESC
子查询就是把子sql语句查询出来当做一张表,再与另外的表关联查询