I'm getting an error on this Presto SQL code in subscribes and unsubscribes function and variable names:
SELECT
emailaddress,
firstname,
lastnamename,
role,
status,
optindate,
optinsource,
optoutdate,
optoutreason,
SUM(subscribes) AS total_subscribes,
SUM(unsubscribes) AS total_unsubscribes
FROM
(SELECT
emailaddress,
firstname,
lastnamename,
role,
status,
optindate,
optinsource,
optoutdate,
optoutreason,
1 as subscribes
FROM
table_subscribes
UNION ALL
SELECT
emailaddress,
firstname,
lastnamename,
role,
status,
optindate,
optinsource,
optoutdate,
optoutreason,
1 AS unsubscribes
FROM
table_unsubscribes) all
GROUP BY
emailaddress, firstname, lastnamename,
role, status, optindate, optinsource,
optoutdate, optoutreason,
I would like to get sum of total subscribes and total unsubscribes from each table combined and group by other attributes into resulting table
UNIONwill only keep the column namaes of the first query, the rest gets lost, so add all columns to both query of theUNIONand all will be fineIf you want a totle of all subscribers yyou need, with out
GROUp BY