SQL查询通过消除值将2列合并为1列 [英] SQL Query Merge 2 Columns Into 1 Column By Eliminating Value
本文介绍了SQL查询通过消除值将2列合并为1列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的数据
我曾尝试将列合并为一列而没有 110,但我的输出是这样的:
I have tried to merge the columns into one column without 110, but my output is like this:
PS:卖7和卖8不包含110,我不想显示
PS: Selling 7 and Selling 8 is not contains 110, I didn't want to show it
我的查询:
select name,
(case when credit_code <> 110 then credit_code
when debit_code <> 110 then debit_code
end) as code from t;
我的预期输出是这样的:
My expected output is like this:
如何像我预期的输出一样查询?
How to query like my expected output?
推荐答案
如果您只想要其中一列包含 110 的行,请使用 where
子句:
If you only want rows that have a 110 in one of the columns, use a where
clause:
select name,
(case when credit_code <> 110 then credit_code
when debit_code <> 110 then debit_code
end) as code
from t
where 110 in (credit_code, debit_code);
这篇关于SQL查询通过消除值将2列合并为1列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文