Присоединяйтесь к полям массива в BigQuery - PullRequest
0 голосов
/ 20 сентября 2018
We have tables Table1 and Table2

<b>Table 1</b>

ID name  subject      
1  xxx   physics   
         maths
         chemistry
2  yyy   physics   
         maths
         chemistry
<b>Table 2</b>

Id   Marks
1    70
     67
     88
2    90
     99
     89

We need to join the above two tables like this format with condition Table1.Id=Table2.Id,

Id    name   subject       Marks
1     xxx    physics       70
             maths         67
             chemistry     88
2     yyy    physics       90
             maths         99
             chemistry     89

1 Ответ

0 голосов
/ 20 сентября 2018
#standardSQL
WITH `project.dataset.table1` AS (
  SELECT 1 id, 'xxx' name, ['physics', 'maths', 'chemistry'] subject UNION ALL
  SELECT 2, 'yyy', ['physics', 'maths', 'chemistry'] 
), `project.dataset.table2` AS (
  SELECT 1 id, [70, 67, 88] marks UNION ALL
  SELECT 2, [90, 99, 89] 
)
SELECT *
FROM `project.dataset.table1` t1
JOIN `project.dataset.table2` t2
USING(id)

с результатом

Row id  name    subject     marks    
1   1   xxx     physics     70   
                maths       67   
                chemistry   88   
2   2   yyy     physics     90   
                maths       99   
                chemistry   89   
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...