【发布时间】:2021-06-12 00:49:57
【问题描述】:
我有一张如下表:
| customerId | orderNo | transactionCode | transactionSubCode |
|---|---|---|---|
| 123123123 | ABC-1234 | null | null |
| 123123123 | XYZ-123 | null | null |
| 123123123 | DEF-456 | null | null |
| 123123123 | HYT-111 | 12a8ksabbc | 999123xxxx11 |
| 123123123 | ZZZ-999 | null | null |
| 333333334 | XYC-777 | null | null |
| 333333334 | XYZ-331 | null | null |
| 333333334 | XYZ-334 | 13a7kcssaf | null |
| 333333334 | XYZ-655 | null | 76612yyyas33 |
我想将 transactionSubCode 列上的现有值分配给同一列的所有空值,基于具有相同值的列,即 customerId 在我们的例子中。所以决赛桌的结果如下:
| customerId | orderNo | transactionCode | transactionSubCode |
|---|---|---|---|
| 123123123 | ABC-1234 | null | 999123xxxx11 |
| 123123123 | XYZ-123 | null | 999123xxxx11 |
| 123123123 | DEF-456 | null | 999123xxxx11 |
| 123123123 | HYT-111 | 12a8ksabbc | 999123xxxx11 |
| 123123123 | ZZZ-999 | null | 999123xxxx11 |
| 333333334 | XYC-777 | null | 76612yyyas33 |
| 333333334 | XYZ-331 | null | 76612yyyas33 |
| 333333334 | XYZ-334 | 13a7kcssaf | 76612yyyas33 |
| 333333334 | XYZ-655 | null | 76612yyyas33 |
我尝试过使用不同的方法进行自连接,但无论如何都无法获得预期的结果。
【问题讨论】:
标签: sql google-bigquery