value_counts(value, frequency)
The table stores a distribution in compressed form: value appeared
frequency times. Return its arithmetic mean as mean_value, without
expanding it back into one row per observation.
AVG(value) is the wrong answer. It averages the distinct values and ignores
how often each occurred. The mean is the weighted sum over the total count.
Tables
value_counts
value frequency
------ ---------
1.0000 100
2.0000 10
3.0000 5
4.0000 1
Expected result
mean_value
----------
1.19827586
Sign in to write and run your own code.
SELECT query