James Joshua Street
James Joshua Street

Reputation: 3419

how to get count of total number of rows following a group by?

I wanted to group some data and then count the number of rows after the duplicate data has been combined into groups.

data:

idx 
7706
7706
1000

want to return total count = 2

 select count(*) (
             select nb.idx
             group by nb.idx
             ) as test

First thing that came to mind was this.

and then I saw someone do this

select count(*) over() group by nb.idx

I'm not sure I totally understand this second one, but I wanted to try various things and compare the speed of the various methods.

Upvotes: 0

Views: 41

Answers (2)

Kiran Patil
Kiran Patil

Reputation: 339

Try below query..

select count(*), nb.idx from table_name
 group by nb.idx

Upvotes: 0

Fahmi
Fahmi

Reputation: 37473

use count(distinct idx)

select count(distinct idx)
from tablname

Upvotes: 1

Related Questions