Skip to content
Advertisement

Best way to count occurrences in a table?

I have a table with some key values occurring in one or more columns. Each value can occur zero or more times in each row. How do I efficiently calculate number of occurrences of each value in the entire table?

example:

desired result:

for reference, table has 6 columns, 50K rows, and 2000 distinct values scattered across.

Advertisement

Answer

One idea is to select all the values into a union, then count:

something like:

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