I wrote this SQL query:
SELECT P.city, D.month_name, SUM(F.number_resolved) OVER W AS "number of positive cases" FROM public.phu_location_dimension AS P JOIN public.fact_table AS F ON P.phu_surrogate_key = F.phu_location_surrogate JOIN public.date_dimension AS D ON D.date_surrogate = F.reported_date_surrogate GROUP BY P.city, D.month_name WINDOW W AS (PARTITION BY P.city ORDER BY D.date_actual RANGE BETWEEN INTERVAL '1' MONTH PRECEDING AND INTERVAL '1' MONTH FOLLOWING) ORDER BY P.city However, I get the error
ERROR: column "f.number_resolved" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT P.city, D.month_name, SUM(F.number_resolved) over W...
I am using the number resolved in an aggregate function, so why is there an error. Can someone please help with this ?
https://stackoverflow.com/questions/66739546/why-do-i-get-a-an-error-that-a-column-must-appear-in-an-aggregate-or-group-by-cl March 22, 2021 at 10:20AM
没有评论:
发表评论