繁体   English   中英

SQL查询通过消除选定值将2列合并为1列

[英]SQL Query Merge 2 Columns Into 1 Column By Eliminating Selected Value

我有这样的数据:

在此处输入图片说明

如何在没有110的情况下将列合并为一列? 像这样:

在此处输入图片说明

简单的用case 对于您的数据,这似乎有效:

select name,
       (case when credit_code = 110 then debit_code else credit_code end)
from t;

如果两者都可以是110 ,那么你会想要:

select name,
       (case when credit_code <> 110 then credit_code
             when debit_code <> 110 then debit_code
        end) as code
from t;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM