COUNT(*) returning multiple rows instead of just one

后端 未结 4 1710
春和景丽
春和景丽 2020-12-16 23:19

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

Should return 1078.

4条回答
  •  太阳男子
    2020-12-16 23:53

    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`
    

提交回复
热议问题