I have:
| id | value |
|---|---|
| 1 | 123 |
| 1 | 124 |
| 1 | 125 |
| 2 | 126 |
| 2 | 127 |
| 2 | 127 |
| 3 | 128 |
| 3 | 128 |
| 3 | 128 |
I want an aggregation like:
| id | distinct_count | total_distinct | percentage |
|---|---|---|---|
| 1 | 3 | 6 | 0.5 |
| 2 | 2 | 6 | 0.33 |
| 3 | 1 | 6 | 0.167 |
I tried applying a window over clause like this:
SELECT id,
COUNT(DISTINCT value) AS distinct_count,
COUNT(DISTINCT value) OVER () AS total_distinct,
COUNT(DISTINCT value) / COUNT(DISTINCT value) OVER () AS percentage
FROM have
GROUP BY id
but it seems it is not implemented yet.
is there a way to achieve this without a join?