我从table1:
SELECT table1.id, COUNT(commentTable1.id) AS CNT3, COUNT(photoTable1.id) AS CNT2, COUNT(fileTable1.id) AS CNT3 FROM table1
LEFT JOIN commentTable1 ON...
LEFT JOIN photoTable1 ON...
LEFT JOIN fileTable1 ON ...
如何正确使用GROUP BY
每个COUNT
?现在我得错了CNT3
答案 0 :(得分:0)
您无法按计数进行分组,因此我假设您按table1.id
SELECT table1.id, COUNT(commentTable1.id) AS CNT3, COUNT(photoTable1.id) AS CNT2, COUNT(fileTable1.id) AS CNT3 FROM table1
LEFT JOIN commentTable1 ON...
LEFT JOIN photoTable1 ON...
LEFT JOIN fileTable1 ON ...
GROUP BY table1.id