PostgreSQL不断在FILTER上抛出语法错误

我做了比较2结果的查询

SELECT ROUND((COUNT(*)::decimal/(SELECT COUNT(*) FROM dashboard.event WHERE cast(event_start_adj AS DATE) = '2020-04-05')*100),2)
FROM dashboard.event
WHERE cast(event_start_adj AS DATE) = '2020-04-05'
AND planned = 'PLANNED'
GROUP BY planned'

The query above outputs 47.30 for the PLANNED Column while the next query outputs 52.70:

SELECT ROUND((COUNT(*)::decimal/(SELECT COUNT(*) FROM dashboard.event WHERE cast(event_start_adj AS DATE) = '2020-04-05')*100),2)
FROM dashboard.event
WHERE cast(event_start_adj AS DATE) = '2020-04-05'
AND planned = 'UNPLANNED'
GROUP BY planned

And this is the query I have made to compare the result of these 2 and make the column PLANNED and UNPLANNED become row:

SELECT
   unnest(array['colPlanned', 'colUnplanned']) AS months,
   unnest(array[col_planned, col_unplanned]) AS values
FROM(
    SELECT
        ROUND((
            COUNT(*)::decimal / (
                SELECT COUNT(*) FROM dashboard.event WHERE cast(event_start_adj AS DATE) = '2020-04-05') * 100)
              FILTER (WHERE cast(event_start_adj AS DATE) = '2020-04-05' AND planned = 'PLANNED'),2) AS col_planned,
        ROUND((
            COUNT(*)::decimal / (
                SELECT COUNT(*) FROM dashboard.event WHERE cast(event_start_adj AS DATE) = '2020-04-05') * 100)
              FILTER (WHERE cast(event_start_adj AS DATE) = '2020-04-05' AND planned = 'UNPLANNED'),2) AS col_unplanned
    FROM dashboard.event
    )t

Postgresql不断向我抛出语法错误,但是在检查完我所有的打开和关闭()后就可以了。 有什么我想念的吗?

显示的错误:

enter image description here

评论