Skip to content
Advertisement

How to count number of groups?

I have a table as follow:

I want to count the number of distinct g_n. (Here it’s 3.)

I have tried with:

But it gives me the number of items per group.

How can I count the number of distinct g_n?

Advertisement

Answer

Use count(distinct):

There is no need to aggregate using group by for this result.

Note: This ignores NULL values. If you want to count them as well, then:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement