Home > Software engineering >  bigquerqy sql link a common grid_id between groups
bigquerqy sql link a common grid_id between groups

Time:03-26

The starting table.

with t1 as 
(
Select 'obrien-t j' lname_forename_long,11 grid_id_ct ,'grid.416153.4' grid_id,2 name_seq ,1 group_seq UNION ALL
Select 'obrien-t j',1,'grid.1002.3',1,1 UNION ALL
Select 'obrien-terence',2,'grid.1008.9',1,2 UNION ALL
Select 'obrien-terence',4,'grid.416153.4',2,2 UNION ALL
Select 'obrien-terence',1,'grid.484852.7',3,2 UNION ALL
Select 'obrien-terence j',14,'grid.1002.3',1,3 UNION ALL
Select 'obrien-terence j',25,'grid.1008.9',2,3 UNION ALL
Select 'obrien-terence j',3,'grid.1019.9',3,3 UNION ALL
Select 'obrien-terence j',9,'grid.1623.6',4,3 UNION ALL
Select 'obrien-terence j',40,'grid.237081.f',5,3 UNION ALL
Select 'obrien-terence j',1,'grid.267362.4',6,3 UNION ALL
Select 'obrien-terence j',2,'grid.414094.c',7,3 UNION ALL
Select 'obrien-terence j',1,'grid.416060.5',8,3 UNION ALL
Select 'obrien-terence j',36,'grid.416153.4',9,3 UNION ALL
Select 'obrien-terence j',4,'grid.453219.8',10,3 UNION ALL
Select 'obrien-terence j',3,'grid.454055.5',11,3 UNION ALL
Select 'obrien-terence j',6,'grid.474069.8',12,3 UNION ALL
Select 'obrien-terence j',13,'grid.481253.9',13,3 UNION ALL
Select 'obrien-terence john',1,'grid.1002.3',1,4 UNION ALL
Select 'obrien-terence john',1,'grid.1008.9',2,4 UNION ALL
Select 'obrien-terence john',1,'grid.1623.6',3,4 UNION ALL
Select 'obrien-terence john',1,'grid.237081.f',4,4 UNION ALL
Select 'obrien-terence john',2,'grid.416153.4',5,4 UNION ALL
Select 'obrien-terrence',2,'grid.416153.4',1,5 UNION ALL
Select 'obrien-terrence j',1,'grid.416153.4',1,6 UNION ALL
Select 'obrien-terry',1,'grid.137628.9',1,7 UNION ALL
Select 'obrien-terry',2,'grid.237081.f',2,7 UNION ALL
Select 'obrien-terry',1,'grid.267362.4',3,7 UNION ALL
Select 'obrien-timothy',1,'grid.496867.2',1,8 UNION ALL
Select 'obrien-timothy',3,'grid.6142.1',2,8 
)
select * from t1;
lname_forename_long grid_id_ct grid_id name_seq group_seq
obrien-t j 1 grid.1002.3 1 1
obrien-t j 11 grid.416153.4 2 1
obrien-terence 2 grid.1008.9 1 2
obrien-terence 4 grid.416153.4 2 2
obrien-terence 1 grid.484852.7 3 2
obrien-terence j 14 grid.1002.3 1 3
obrien-terence j 25 grid.1008.9 2 3
obrien-terence j 3 grid.1019.9 3 3
obrien-terence j 9 grid.1623.6 4 3
obrien-terence j 40 grid.237081.f 5 3
obrien-terence j 1 grid.267362.4 6 3
obrien-terence j 2 grid.414094.c 7 3
obrien-terence j 1 grid.416060.5 8 3
obrien-terence j 36 grid.416153.4 9 3
obrien-terence j 4 grid.453219.8 10 3
obrien-terence j 3 grid.454055.5 11 3
obrien-terence j 6 grid.474069.8 12 3
obrien-terence j 13 grid.481253.9 13 3
obrien-terence john 1 grid.1002.3 1 4
obrien-terence john 1 grid.1008.9 2 4
obrien-terence john 1 grid.1623.6 3 4
obrien-terence john 1 grid.237081.f 4 4
obrien-terence john 2 grid.416153.4 5 4
obrien-terrence 2 grid.416153.4 1 5
obrien-terrence j 1 grid.416153.4 1 6
obrien-terry 1 grid.137628.9 1 7
obrien-terry 2 grid.237081.f 2 7
obrien-terry 1 grid.267362.4 3 7
obrien-timothy 1 grid.496867.2 1 8
obrien-timothy 3 grid.6142.1 2 8

END RESULT enter image description here

  • Related