[thelist] counting frequency of distinct values in MSSQL

Joel D Canfield joel at spinhead.com
Sat Sep 13 14:10:40 CDT 2003


It's my weekend to be brain dead, I guess. I need to count the frequency
of each unique numerical value in a table.

F'rinstance, if the table contained

1
3
2
3
5
4
2
1
3

I'd like to see the results

1 occurs 2 times
2 occurs 2 times
3 occurs 3 times
4 occurs 1 time
5 occurs 1 time

I'm working primarily with decimals between 0 and 1, but values could
conceivably be any numerical value.

I've toyed with COUNT and COUNT DISTINCT, but I can't figure out how to
count the frequency of each unique value.

Thanks once again.

spinhead


More information about the thelist mailing list