I am trying to sum two tables sales + waste with results grouped by week and year. If I run each section by itself I get accurate results, but when I try my current query I get an error of "[42601] ERROR: subquery must return only one column"
This is what I currently have...
SELECT
(
SELECT date_part('week', w."createdAt"),
SUM("Quantity")
FROM waste as w
WHERE date_trunc('year', w."createdAt"::timestamptz at time zone 'America/Denver') =
date_trunc('year', current_date - interval '1 year')
group by 1
)
+
(
SELECT date_part('week', sh.”createdAt"),
SUM(quantity)
FROM sales_hourly as sh
WHERE date_trunc('year', sh."createdAt"::timestamptz at time zone 'America/Denver') =
date_trunc('year', current_date - interval '1 year')
group by 1
) AS weekly_total