I m trying to get SUM of two numbers by following following logic: x = y + j based on this logic I wrote presto query using SUM() function in order to get SUM of x and y but I got Presto syntax error
SELECT
SUM(sum(CASE
WHEN source = 'x' THEN num_tasks
ELSE 0
END) + sum(CASE WHEN source = 'y' THEN num_tasks ELSE 0 END)) as total
Error notice Presto query failed. Error: SYNTAX_ERROR: Cannot nest aggregations inside aggregation 'sum': ["sum"((CASE WHEN (source = 'y') THEN count ELSE 0 END)), "sum"((CASE WHEN (source = 'x') THEN num_tasks ELSE 0 END))]
Sum
withinSum
the way you want according to the SQL documentation. Instead, try something likeSUM(SELECT FIELD_1, FIELD_2 from TABLE_1, TABLE_2)
. Then you can pull back the columns you want to sum up all at once – Michael Platt