编写SQL查询实现基于关联列填充number字段NULL值的需求
数据处理需求与结果
原始数据表格
| master_code | id | type | number |
|---|---|---|---|
| null | abcsjjjjsUV | doo | 852456 |
| abcsjjjjsUV | iydjfjdww | too | 951753 |
| abcsjjjjsUV | retslslfdf | too | null |
number字段处理规则
- 当
type = 'doo'时,保留number字段的原始值; - 当
type = 'too'且number不为null时,保留number字段的原始值; - 当
type = 'too'且number为null时,将该记录的master_code与type = 'doo'的记录的id进行匹配,用匹配到的记录的number值填充当前null。
预期处理结果表格
| master_code | id | type | number |
|---|---|---|---|
| null | abcsjjjjsUV | doo | 852456 |
| abcsjjjjsUV | iydjfjdww | too | 951753 |
| abcsjjjjsUV | retslslfdf | too | 852456 |
内容的提问来源于stack exchange,提问作者Jainam Furia
相关产品推荐
相关产品推荐

