gpt4 book ai didi

mysql - 如何计算表中每一行的行数?

转载 作者:行者123 更新时间:2023-11-29 23:19:22 30 4
gpt4 key购买 nike

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

如何正确地对每个 COUNT 使用 GROUP BY ?现在我得到了错误的 CNT3

数量

最佳答案

您无法按计数分组,因此我假设您按 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

关于mysql - 如何计算表中每一行的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27463042/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com