Here is an example table that mimics my scenario:
COL_1 COL_2 COL_3 COL_4 LAST_COL
A P X NY 10
A P X NY 11
A P Y NY 12
A P Y NY 13
A P X NY 14
B Q X NY 15
B Q Y NY 16
B Q Y CA 17
B Q Y CA 18
LAST_COL is the primary key, so it will be different each time.
I want to ignore LAST_COL and collect some statistics related to the other four columns.
Basically, I have millions of rows in my table, and I want to know which set COL_1, COL_2, COL_3 and COL_4
has the most rows.
So, I need a query that can print me all unique lines with their number of occurrences.
COL_1 COL_2 COL_3 COL_4 TOTAL
A P X NY 3
A P Y NY 2
B Q X NY 1
B Q Y NY 1
B Q Y CA 2
Thanks to everyone who helps me with this.
* I use MS SQL if that matters.
source
share