如何计算表中每行的行数?

时间:2014-12-13 20:00:52

标签: mysql sql

我从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

1 个答案:

答案 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