Skip to content
Advertisement

How to aggregate and group by in each column?

I have this table:

I’d like to summarize major and minor columns to get this result:

Is there any way to achieve this? I tried:

But it didn’t count each number.

Advertisement

Answer

You may achieve this using window functions.

major minor major_count minor_count
A a 3 2
A b 3 1
B c 2 1
B d 2 1

View on DB Fiddle

Let me know if this works for you.

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