SELECT v.name,COUNT(DISTINCT f.ID)AS family,COUNT(DISTINCT p.ID)AS person ,COUNT(DISTINCT pa.ID) AS man,COUNT(DISTINCT ps.ID)AS woman ,COUNT(DISTINCT c.id)AS car
FROM village AS v
LEFT JOIN family AS f ON f.villageID=v.ID AND f.building='3'
LEFT JOIN personnel AS p ON p.familyid=f.ID AND f.building='3'
LEFT JOIN personnel AS pa ON pa.familyid=f.ID AND pa.sex='男' AND f.building='3'
LEFT JOIN personnel AS ps ON ps.familyid=f.ID AND ps.sex='女' AND f.building='3'
LEFT JOIN car AS c ON c.familyid=f.ID AND f.building='3'
where  v.ID='d66cf963-2354-11e8-b8a0-f48e38f841f1'
GROUP BY f.building

已解决

 

 

https://www.cnblogs.com/kerrycode/p/5935704.html
这篇帖子对join的各种用法讲解比较清晰,可以参考一下

相关文章:

  • 2022-03-04
  • 2022-02-12
  • 2021-07-24
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-07-03
相关资源
相似解决方案