简体   繁体   English

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

[英]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?如何在没有110的情况下将列合并为一列? Like this:像这样:

在此处输入图片说明

Simply use case .简单的用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:如果两者都可以是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.

相关问题 SQL查询通过消除值将2列合并为1列 - SQL Query Merge 2 Columns Into 1 Column By Eliminating Value Sql 查询将所有列合并为单个列 - Sql query to merge all columns into a single column 在一个 SQL 查询中合并两个表中的两列,并使用表中的值作为列名 - Merge two columns from two tables in one SQL query and use value in tables as column name SQL按多列中的值对分组并消除相同的元组 - SQL grouping by value pairs in multiple columns and eliminating identical tuples SQL查询以获取按列分组的列的最新非空值 - SQL query to get latest non null value of columns grouping by a column 子查询中的选定列(多列)未显示 - Selected columns in sub query(Multiple column) are not showing WordPress查询结果,其中所有列的值均与所选ID的列相同 - WordPress query results where all columns have the same value as column of selected id 通过消除条件显示结果的 SQL 查询 - SQL Query on displaying a result by eliminating on a condition 如果第一列中存在第二列值,则从两列中选择值的Spark Sql查询 - spark Sql query for selecting values from two columns if second column value is present in first column 如果两个现有列匹配,则SQL查询添加新列,并从另一列添加值 - SQL query add new column if two existing columns matches and add value from another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM