简体   繁体   中英

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

I have a data like this:

在此处输入图片说明

How to merge the columns into one column without 110? Like this:

在此处输入图片说明

Simply use case . For your data, this seems to work:

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

If both could be 110 , then you would want:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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