匹配条件时更改列值 [英] Change column value when matching condition

查看:66
本文介绍了匹配条件时更改列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当其他条件匹配时,我才需要替换列中的NULL值.

I need to replace a NULL value in a column only when other conditions are matched.

Columns: Parent, Child, flag01, lag02

父列具有许多NULL值,但是我只想在flag01flag02为"ok"时才替换null值.

Parent columns has many NULL values, but I want to replace the null values only when flag01 and flag02 is "ok".

如果flag01flag02都为"Ok",并且Parent为NULL,则替换为'CT_00000'.否则,保留原始值(当NOT NULL时).

If flag01 and flag02 are both "Ok" and Parent is NULL, replace to 'CT_00000'. Else, keep the original value (when NOT NULL).

推荐答案

因此,尽管我想要一条select语句.

So as I though you want a select statement.

select case when (parent is null and flag01 = 'OK' and flag02 = 'OK') 
       then 'CT_00000'
       else parent end as columnSomeName,
       Child, flag01, lag02
 from yourTable

这篇关于匹配条件时更改列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆