Skip to content
Advertisement

Value counts for every field of a table

In PostgresSQL, I am trying to get the value counts of every field and value pair. For illustration, I have 2 columns, but I really have 100 columns. So, I need a programmatic solution.

For a table,

I know that

gives me what I want for one column:

But how can I programmatically iterate through all the columns and generate this, for example:

Advertisement

Answer

Use grouping sets:

If you are determined to get the result in the mentioned format:

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