LoginSignup
1
0

More than 3 years have passed since last update.

BigQueryで便利だったことSQLメモ

Posted at

SQLをちょっと試したい時のUNNEST

都合良いデータが無いときはunion allを繋げて複数行をテストデータ作ってたけど、unnestを使えば短いコードでテストデータが作れる。

unnestを使ったSQL確認方法
select a, b 
from
  unnest([null, 1]) as a,
  unnest(['x', 'y']) as b

-- SQL結果
|  | a   | b |
| 1  | null| x |
| 2  | null| y |
| 3  | 1   | x |
| 4  | 1   | y |

-- 同じデータをunion allで作った場合
select a, b
from (
            (select null as a)
  union all (select 1 as a)
),
(
            (select 'x' as b)
  union all (select 'y' as b)
)  
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0