COUNT(*)返回多行而不是只返回一行 [英] COUNT(*) returning multiple rows instead of just one

查看:128
本文介绍了COUNT(*)返回多行而不是只返回一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么COUNT()返回多行,当我只需要我查询生成多少行的总数?



返回1078。



>

COUNT()正常工作。 当组通过子句时, count()给出 GROUP BY 。如果您希望获取包含 group by 的查询中的行数,请改用它作为子查询。



像:

  SELECT COUNT(*)FROM(SELECT * FROM`table` 
GROUP BY`column1 `)AS`a`


Why does COUNT() return multiple rows when I just need the total count of how many rows my query generates?

Should return 1078.

解决方案

The COUNT() is working as expected. When you put a group by clause, the count() gives you the result for GROUP BY. If you wish to get the count of rows in a query that includes group by, use it as a subquery instead.

Something like:

SELECT COUNT(*) FROM (SELECT * FROM `table`
                      GROUP BY `column1`) AS `a`

这篇关于COUNT(*)返回多行而不是只返回一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆