I'm having an issue figuring out how I should be ending this query because I keep getting an error in BigQuery.
It's a relatively large query with several unions all following pretty much the same syntax. When I go to end the query following the subquery I am getting an error.
Error: Syntax error: Expected ")" but got end of statement at [133:54]
All of the unions follow the same syntax—just from separate tables
UNION ALL
SELECT
report_date,
device_category,
data_source,
source,
medium,
LOWER(campaign_name) AS campaign_name,
conversion_type,
Brand,
goal_completion_1,
impressions,
clicks,
cost,
conversions,
profile
FROM (
SELECT
report_date,
device_category AS device,
data_source,
CASE
WHEN data_source = 'Google Ads' THEN 'google'
WHEN data_source = 'Adroll' THEN 'adroll'
WHEN data_source = 'Facebook Ads' THEN 'facebook'
WHEN data_source = 'Bing Ads' THEN 'bing'
ELSE NULL
END AS source,
CASE
WHEN data_source = 'Google Ads' THEN 'cpc'
WHEN data_source = 'Adroll' THEN 'display'
WHEN data_source = 'Facebook Ads' THEN 'paid_social'
WHEN data_source = 'Bing Ads' THEN 'cpc'
ELSE NULL
END AS medium,
0 AS goal_completion_1,
0 AS impressions,
0 AS clicks,
0 AS cost,
conversions,
profile
FROM
`table`
)
I have a similar query to this except it ends with a where statement and it seems to run fine- but when I add anything after the from I still get the same error.
WHERE conversion_type <> 'Calls from ads'