Mysql 如何计算包含GROUPBY子句的行数?
我编写了以下查询,其中使用了Mysql 如何计算包含GROUPBY子句的行数?,mysql,sql,join,group-by,count,Mysql,Sql,Join,Group By,Count,我编写了以下查询,其中使用了groupby子句 select MAX(r.network->>"$[0].name") , s.server, MAX(s.ipAddr), from table1 e inner join table2 s on e.objectId = s.envId inner join resources r on e.objectId = r.envId inner join tpg
groupby
子句
select MAX(r.network->>"$[0].name") , s.server, MAX(s.ipAddr),
from table1 e
inner join table2 s
on e.objectId = s.envId
inner join resources r
on e.objectId = r.envId
inner join tpgs g
on e.accountId = g.objectId
inner join msgTable a
on a.id = (select max(a.id) from msgTable a where a.logId = s.AuditId)
GROUP BY s.server
ORDER BY dateSubmitted DESC ;
我想计算上述查询返回的行数
以下查询没有给出计数
select count(*)
from table1 e
inner join table2 s
on e.objectId = s.envId
inner join resources r
on e.objectId = r.envId
inner join tpgs g
on e.accountId = g.objectId
inner join msgTable a
on a.id = (select max(a.id) from msgTable a where a.logId = s.AuditId)
GROUP BY s.server;
我知道您想要计算聚合查询返回的行数 如果是这样,则需要另一个聚合级别,即将查询转换为子查询,然后在外部查询中计数:
select count(*) no_records
from (
select 1
from table1 e
inner join table2 s
on e.objectId = s.envId
inner join resources r
on e.objectId = r.envId
inner join tpgs g
on e.accountId = g.objectId
inner join msgTable a
on a.id = (select max(a.id) from msgTable a where a.logId = s.AuditId)
group by s.server
) t;
注意:由于我们只需要计算得到的记录数,因此实际上不需要在
SELECT
子句中进行其他计算<代码>选择1就足够了。您要计算的是什么?你的意思是第一次查询返回的行数吗?在没有任何解释的情况下发布一个中断的查询对我们没有帮助。您想计算什么???查询不完整,但没有中断@GMB帮了我的忙,这正是我所需要的