从 SQL Server 表中删除重复的空值

问题描述 投票:0回答:1

问题表

col1   col2  col3 col4
1      null  a    null
1      b     null null
1      null  null c
2      aa    null null
2      null  bb   null

需要输出

col1   col2  col3 col4
1      b     a    c
2      aa    bb   null

请帮忙进行 SQL 查询

我想删除空值并合并单行中的列

sql sql-server sql-server-2012
1个回答
0
投票

你只需要

group by

select 
col1   
max(col2) col2,  
max(col3) col3,
max(col4) col4
from Issue 
group by col1   
© www.soinside.com 2019 - 2024. All rights reserved.