I wrote this query that suppose to count the working days in a month but I get the following error:
[42883] ERROR: operator does not exist: double precision + interval Hinweis: No operator matches the given name and argument types. You might need to add explicit type casts. Position: 305
The date is a timestamp and this is the function below serves as the denominator to normalize sales:
(count(((date_part('month',date))+ Interval '1 month'- Interval '1 day')-(date_part('month',date)))
filter (where date_part('dow', date) not in (6,0)))
In the end I will have:
select date_part('month', date) as month,
sum(sales)/denominator as Monthly_noralized_sales
from sales;
(date_part('month',date) + Interval '1 month'- Interval '1 day') - (date_part('month',date))
is supposed to do. Additionally it seems pointless to pass that expression to thecount()
aggregate as it is essentially the same ascount(date)
- i.e. it will include all rows wheredate is not null
. Which is also achieved by yourfilter
anyway as that will also exclude rows wheredate
is null. So it seems you can simplify that tocount(*) filter (where date_part(..) not in (..))