Skip to content
Advertisement

Percentage distribution of column occurence?

I am looking for a way to calculate the distribution of column values in my table. e.g. if I have two rows containing “red” and “blue”, each should have 50%. I want to count the occurence of col and compare that to the overall amount of rows.

My attempt:

Any help? Thank you!

Advertisement

Answer

Just pay attention to integer division. I often just multiply by 1.0:

I also notice that the denominator needs to be SUM(COUNT(*)) rather than COUNT(*). Your version just divides by the number of rows in the result set — that is, the number of values of log_domain.

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