COUNT(DISTINCT …) OVER (PARTITION BY …) in Postgrsql

  Kiến thức lập trình

I have the following query:

SELECT s.first_field,
       s.second_field,
       t.third_field,
       s.fourth_field,
       ROUND(
               (SUM(mt.volume) * 100.0 /
                 SUM(mt.volume) / COUNT(DISTINCT mt.question_id) OVER (PARTITION BY s.first_field, s.second_field, s.fourth_field)),
               2
       ) AS score,
       fsd.volume
FROM my_table mt
         LEFT JOIN second s
                   ON mt.second_id = s._id
         LEFT JOIN third t
                   ON mt.third_id = t._id
WHERE s.fourth_field IS NOT NULL
  AND s.fifth_field IS NOT NULL
  AND s.fifth_field = 'Test'
GROUP BY s.first_field, s.second_field, t.third_field, s.fourth_field, mt.volume
;

But I’m getting the following error: [0A000] ERROR: DISTINCT is not implemented for window functions

I don’t know what to try as I don’t use SQL too much

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT