如何将多个sql行连接成一行

时间:2018-06-07 21:46:38

标签: sql

我有来自查询的输出:

Select hostname,support1,support2 From hostnames where hostname in ('C')

C | NULL |  NULL 
C | NULL |  B 
C | A | NULL  
C | A | B 

如您所见,有NULL | BA | NULL。 我需要输出:

C | A | B 

(将两行合并为一行) 这该怎么做 ? 感谢

1 个答案:

答案 0 :(得分:1)

您可以使用聚合:

Select hostname, max(support1) as support1, max(support2) as support2
From hostnames
where hostname in ('C') 
group by hostname;