【发布时间】:2026-01-07 04:05:02
【问题描述】:
是否可以结合 OVER(PARTITION BY id) 之类的窗口函数计算不同的值?目前我的查询如下:
SELECT congestion.date, congestion.week_nb, congestion.id_congestion,
congestion.id_element,
ROW_NUMBER() OVER(
PARTITION BY congestion.id_element
ORDER BY congestion.date),
COUNT(DISTINCT congestion.week_nb) OVER(
PARTITION BY congestion.id_element
) AS week_count
FROM congestion
WHERE congestion.date >= '2014.01.01'
AND congestion.date <= '2014.12.31'
ORDER BY id_element, date
但是,当我尝试执行查询时,出现以下错误:
"COUNT(DISTINCT": "DISTINCT is not implemented for window functions"
【问题讨论】:
标签: postgresql window-functions