I have a SQL query I do not quite understand regarding operator precedence:
SELECT
foo,
count(*)
FROM
A
JOIN (SELECT
SUM(IF(bar = 2,1,0)) as bar_sum,
SUM(IF(foo >= 1,1,0)) as foo,
SUM(1) as sum_1
FROM
B
) as sums
GROUP BY
id,
bar_sum,
foo,
sum_1
ON A.id = B.id
does the GROUP BY
from outer brace really apply to the inner one?
Note, I need to port this SQL from Hive to Spark scala Dataframe API so I really need to get operator precedence right. From What is the execution sequence of Group By, Having and Where clause in SQL Server? it looks like in general this is true, but I did not find any documentation regarding the ()
.