I want to join multiple tables in BigQuery but the solution of Joining multiple tables in bigquery did not help me to get my desired output.
My starting point is the following. I am creating 5 individual tables that are displaying each rating values possible for a specific page. See examplary output here:
The table are created in the following way:
#standardSQL
CREATE TEMPORARY FUNCTION tables_in_range(suffix STRING) AS (suffix BETWEEN (
SELECT
FORMAT_DATE('%y%m%d',
DATE('2018-06-01')))
AND (
SELECT
FORMAT_DATE('%y%m%d',
DATE('2018-06-30'))));
SELECT
h.page.pagePath AS page,
Count(h.eventInfo.eventLabel)as five_star
FROM
`table.ga_sessions_20*` AS t,
t.hits AS h
WHERE
h.eventInfo.eventAction='rating'
AND h.eventInfo.eventLabel ='5'
AND tables_in_range(_TABLE_SUFFIX)
AND REGEXP_CONTAINS(h.page.pagePath,
r'/xyz/')
AND h.type='EVENT'
group by 1
When joining the tables as described here Joining multiple tables in bigquery I unfortunately do not get the expected result. Instead the Join is only looking at Pages that all 5 tables have in common - meaning that these are pages that have a rating in each of the five possible values ranging from 1-5. See example output below. joint table results
select
five_star.page as page,
five_star.five_star as five_star,
four_star.four_star as four_star,
three_star.three_star as three_star,
two_star.two_star as two_star,
one_star.one_star as one_star
from five_star
join four_star using (page)
join three_star using (page)
join two_star using (page)
JOIN one_star using (page)
What I would like to achieve through my join is a table like this: desired output. The problem I see is that if a page has not received a certain rating it will not be joined in the query atm. Unfortunately, I was not able to find a solution with Union all, Cross Join or left join, so I am very grateful for any support here!