以下是要求,它需要在 SQL 中转换。
我只会收到来自源的一条记录,但我需要验证以下条件并将其拆分为黑斑羚的两行。
从源预期值final_columns
IS ('IC', 'OG', 'BK')
。
我需要检查只有当我接收到的值下面的条件'BK'
在final_columns
。
if (final_columns in ('BK')) {
split into rows based on below conditions
when dr_type = 'IT' THEN dr_cid else dr_pid
when cr_type = 'OR' THEN cr_cid else cr_pid
}
else {
value as it is in source final columns
}
你能试试这个sql吗?我创建了虚拟内联视图来复制数据。
select
case when final_columns in ('BK') AND
case when dr_type = 'IT' THEN dr_cid
when dr_type <> 'IT' THEN dr_pid
when cr_type = 'OR' THEN cr_cid
when cr_type <> 'OR' THEN cr_pid
END
else final_columns
end
from
table,
( select 1 col union all select 1 union all select 2 ) dummy_record_creation
where
case when final_columns in ('BK') then 1 else 2 end = dummy_record_creation.col
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句