Count number of records returned by group by

前端 未结 13 1843
梦毁少年i
梦毁少年i 2020-11-30 20:01

How do I count the number of records returned by a group by query,

For eg:

select count(*) 
from temptable
group by column_1, column_2, column_3, co         


        
13条回答
  •  生来不讨喜
    2020-11-30 20:32

    I know it's rather late, but nobody's suggested this:

    select count ( distinct column_1, column_2, column_3, column_4) 
    from   temptable
    

    This works in Oracle at least - I don't currently have other databases to test it out on, and I'm not so familiar with T-Sql and MySQL syntax.

    Also, I'm not entirely sure whether it's more efficient in the parser to do it this way, or whether everyone else's solution of nesting the select statement is better. But I find this one to be more elegant from a coding perspective.

提交回复
热议问题