如何基于其他字段值使值为空

时间:2017-02-16 14:01:14

标签: sql oracle

有人可以帮助我如何实现以下目标吗?

我得到了以下结果:

APP ¦ CW ¦     DT     ¦ DAY
---------------------------
SKL ¦ 05 ¦ 2017-02-03 ¦ FRI
SKL ¦ 06 ¦ 2017-02-06 ¦ MON
SKL ¦ 06 ¦ 2017-02-07 ¦ TUE
SKL ¦ 06 ¦ 2017-02-08 ¦ WED
SKL ¦ 06 ¦ 2017-02-09 ¦ THU
SKL ¦ 06 ¦ 2017-02-10 ¦ FRI
SKL ¦ 07 ¦ 2017-02-13 ¦ MON
SKL ¦ 07 ¦ 2017-02-14 ¦ TUE
XZU ¦ 05 ¦ 2017-02-03 ¦ FRI
XZU ¦ 06 ¦ 2017-02-06 ¦ MON
XZU ¦ 06 ¦ 2017-02-07 ¦ TUE
XZU ¦ 06 ¦ 2017-02-08 ¦ WED
XZU ¦ 06 ¦ 2017-02-09 ¦ THU
XZU ¦ 06 ¦ 2017-02-10 ¦ FRI
XZU ¦ 07 ¦ 2017-02-13 ¦ MON
XZU ¦ 07 ¦ 2017-02-14 ¦ TUE
WIO ¦ 05 ¦ 2017-02-03 ¦ FRI
WIO ¦ 06 ¦ 2017-02-06 ¦ MON
..
.

而不是以上我想得到这个:

APP ¦ CW ¦     DT     ¦ DAY
---------------------------
SKL ¦    ¦ 2017-02-03 ¦ FRI
SKL ¦ 06 ¦ 2017-02-06 ¦ MON
SKL ¦    ¦ 2017-02-07 ¦ TUE
SKL ¦    ¦ 2017-02-08 ¦ WED
SKL ¦    ¦ 2017-02-09 ¦ THU
SKL ¦    ¦ 2017-02-10 ¦ FRI
SKL ¦ 07 ¦ 2017-02-13 ¦ MON
SKL ¦    ¦ 2017-02-14 ¦ TUE
XZU ¦    ¦ 2017-02-03 ¦ FRI
XZU ¦ 06 ¦ 2017-02-06 ¦ MON
XZU ¦    ¦ 2017-02-07 ¦ TUE
XZU ¦    ¦ 2017-02-08 ¦ WED
XZU ¦    ¦ 2017-02-09 ¦ THU
XZU ¦    ¦ 2017-02-10 ¦ FRI
XZU ¦ 07 ¦ 2017-02-13 ¦ MON
XZU ¦    ¦ 2017-02-14 ¦ TUE
WIO ¦    ¦ 2017-02-03 ¦ FRI
WIO ¦ 06 ¦ 2017-02-06 ¦ MON
..
.   

所以当“DAY”不是“MON”时,我试图将“CW”列清零。这应该有一个简单的解决方案,但直到我还没有找到这样做的方法。

提前致谢。

1 个答案:

答案 0 :(得分:2)

您正在寻找CASE

select APP,
    case when day = 'MON' then CW end cw,
    DT,
    DAY
from your_table;