Reputation: 1
Why am I getting this error since I am trying to run the below?
WITH rakes AS (
SELECT
SUM(tbl.rake) AS rake, usr.site_id
FROM
table1 as tbl
INNER JOIN
user as usr
ON
usr.id= tbl.user_id
WHERE
usr.origin <> 'test'
AND
tbl.created_at>= '2021-01-01'
AND
tbl.created_at< '2021-07-25' GROUP BY usr.site_id ),
fees AS (
SELECT
SUM(fees) AS fees, site_id
FROM
table1
WHERE
csv_date>= '2021-01-01'
AND
csv_date< '2021-07-25' GROUP BY site_id
)
SELECT (COALESCE(r.rake,0) + COALESCE(f.fees,0))::numeric(18,2) AS calc
FROM rakes AS r JOIN
fees AS f
ON r.site_id=f.site_id
WHERE COALESCE(r.site_id, f.site_id) IN ('domain.gr', 'domain.uk','domain.com')
Upvotes: 0
Views: 2740