如何在 ms SQL Server Management 2005 中将列信息合并到一行中



我正在尝试将多行合并为一行。

Office 1    NULL    NULL    12/15/2020
Office 1    NULL    10/15/2008  NULL
Office 1    1949885 NULL        NULL

我正在使用带有 case 语句的内部联接来查询信息。我只是不知道如何将所有数据合并到一行中

我希望我的结果是这样的

Office 1  1949885 10/15/2008 12/15/2020

这是我的查询

select distinct GroupName, (case when userid=1 then data end) as TPI,
(case when userid=4 then data end) as Enrollment_Date,
(case when userid=19 then data end) as Expiration_Date
from offices
inner join userdefinedoff uo on uo.OfficeID=Offices.OfficeID
where userid=1 or userid=4 or userid=19

所有数字数据都存储为字符串。

select
office1column,
max(Col1),
max(COl2)
..
from
table
group by office1column

max/min 将忽略组中的空值,并给出值(如果存在(

最新更新