简体   繁体   English

对于单个表,如何折叠具有互斥列数据的多行

[英]With single table, how do I collapse multiple rows with mutually exclusive column data

I wish to combine rows of a table, with mutually exclusive column values, retaining all columns: For example: 我希望将表的行与相互排斥的列值合并,保留所有列:例如:

Name Data1 Data2 Data3 .... DataN
NAM1  6     NULL  NULL ...   NULL
NAM1  NULL  NULL  7    ...   NULL
NAM2  NULL   8    NULL ...   NULL
NAM3  5     NULL  NULL ...   NULL
NAM3  NULL  NULL   9   ...   NULL
NAM3  NULL   4    NULL ...   NULL
NAM4  etc

The characteristic of the data on each row of the table only 1 of the values Data1 ... DataN will not be NULL 表的每一行上的数据的特性只有值Data1 ... DataN中的1个不会为NULL

I want the results to be 我希望结果是

NAME DATA1 DATA2 DATA3 ... DATAN
NAM1  6     NULL  7    ...  NULL
NAM2  NULL  8     NULL ...  NULL
NAM3  5     4     9    ...  NULL
NAM4
select Name, MAX(Data1), MAX(Data2), MAX(Data3) from test
group by Name

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

相关问题 如何在表中存储互斥值 - how to store a mutually exclusive value in a table 如何:来自互斥的多个 CTE 的 SELECT - How to: SELECT from multiple CTEs that are mutually exclusive 如何将共享一个相同值的多行折叠成一行 PRESTO SQL - How do I collapse multiple rows that shares one identical value into a single row PRESTO SQL 当希望将单行数据放在单列中时,如何联接一个简单的左联接将产生多行的表? - How do join a table where a simple left join will produce multiple rows when the desire is to have a single row the data in a single column? 如何将多行数据选择或放置到单行或单列中? - How do I Select or Place data from multiple rows into a single row or column? 如何构建表模型互斥1:n关系? - How to Structure Table to Model Mutually Exclusive 1:n Relationships? 如何在 pivot 表上将多行合并为一行 - How to collapse multiple rows into one on a pivot table 如何使用互斥的 where 语句选择数据 - How select data using mutually exclusive where statements 如何将多行插入到单个表的多列中 - How to insert multiple rows into multiple column of single table 如何在Access 2010中使用TSQL“折叠”以下列数据? - How do I “collapse” the following column data with TSQL in Access 2010?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM