SQL Server 中的解码问题

发布于 01-20 12:11 字数 2315 浏览 3 评论 0原文

我需要此查询的帮助:

SELECT 
    a.id
    CASE 
        WHEN a.sco = 0 
            THEN DECODE (a.x, 1, '1', 2, '2', 33, '3' null, '0', 0, '0', a.x) 
            ELSE DECODE (a.sco, 1, '1', 2, '2',33, '3' null, '0', 0, '0', a.sco)
    FORMAT a.dt, 'yyyy-MM') as date
    DECODE (a.sco, 1, '1', 2, '2',33, '3' null, '0', 0, '0', a.sco)
    DECODE (a.x, 1, '1', 2, '2',33, '3' null, '0', 0, '0', a.x)
FROM 
    aaa        a

我想根据 sco 的值替换 x 中的值:

when sco = 0 values from x should be 1 if 1, if 2, 2 if 33, 3 if null, 0 if 0, 0
and when sco = 1,1, if 2, 2 if 33, 3 if null, 0 if 0, 0
and when x = 1,1, if 2, 2 if 33, 3 if null, 0 if 0, 0
idscoxdate
001012019-04
002022021-07
0030332009-09
0040null2011-02
005002020-02
001112019-04
002222021-07
00333332009-09
004nullnull2011-02
005202020-02

所需:

idscox日期
001012019-04
002022021-07
003032009-09
004002011-02
005002020-02
001112019-04
002222021-07
003332009-09
004002011-02
005202020年02月

I need help with this query:

SELECT 
    a.id
    CASE 
        WHEN a.sco = 0 
            THEN DECODE (a.x, 1, '1', 2, '2', 33, '3' null, '0', 0, '0', a.x) 
            ELSE DECODE (a.sco, 1, '1', 2, '2',33, '3' null, '0', 0, '0', a.sco)
    FORMAT a.dt, 'yyyy-MM') as date
    DECODE (a.sco, 1, '1', 2, '2',33, '3' null, '0', 0, '0', a.sco)
    DECODE (a.x, 1, '1', 2, '2',33, '3' null, '0', 0, '0', a.x)
FROM 
    aaa        a

I want to replace values from x depending on values of sco:

when sco = 0 values from x should be 1 if 1, if 2, 2 if 33, 3 if null, 0 if 0, 0
and when sco = 1,1, if 2, 2 if 33, 3 if null, 0 if 0, 0
and when x = 1,1, if 2, 2 if 33, 3 if null, 0 if 0, 0
idscoxdate
001012019-04
002022021-07
0030332009-09
0040null2011-02
005002020-02
001112019-04
002222021-07
00333332009-09
004nullnull2011-02
005202020-02

desired:

idscoxdate
001012019-04
002022021-07
003032009-09
004002011-02
005002020-02
001112019-04
002222021-07
003332009-09
004002011-02
005202020-02

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文