How to SUM DISTINCT by other columns? I have a CTE that resulting something like this:
i x y 
A 4 ...
A 4 ... 
A 4 ...
A 4 ...
B 2 ...
B 2 ...
C 3 ...

And already have a query that uses most of them:
WITH cte AS ( ... ) -- above is the example result of the cte
SELECT
    COUNT(DISTINCT (CASE WHEN ... THEN i END)) bla_count1
  , COUNT(DISTINCT (CASE WHEN ... THEN i END)) bla_count2
  , SUM(x)/COUNT(*) bla_average
  -- and much more similar to above
  , -- how to get sum of A, B, C (4+2+3)
FROM cte

How to get the SUM of x DISTINCT by i (4+2+3)?
Modified Fiddle
Nevermind, found a way, by adding one more CTE
WITH cte AS ( ... )
, sum1 AS (
  SELECT i, MAX(x) tot -- or AVERAGE/MIN
  FROM cte
  GROUP BY 1
)
SELECT ...
   , (SELECT SUM(tot) FROM sum1) AS sum1
FROM cte