Ricardo Soria Asked: 2020-10-05 08:48:03 +0800 CST 2020-10-05 08:48:03 +0800 CST 2020-10-05 08:48:03 +0800 CST 如何使用 SQL SERVER 将多条记录合并为一条? 772 我需要这张桌子: 变成了这样:(编辑它作为一个图像使用paint来显示作为一个例子) 数据将始终具有相同的“服务器名称”、共同的日期和时间 sql 1 Answers Voted Best Answer jachguate 2020-10-05T08:57:33+08:002020-10-05T08:57:33+08:00 您需要做的是按某些列分组。在这种情况下,对于serverName和Date,Time例如,此查询将返回您所期望的结果: with Datos as ( select 16 idse, 'LSTKAG72544' serverName, cast('20180928' as date) [DATE], CAST('17:09:59' as time) [TIME], null SQLBrowser, 'Running' W3SVC, null wscsvc union all select 17 idse, 'LSTKAG72544' serverName, cast('20180928' as date) [date], CAST('17:09:59' as time) [time], null SQLBrowser, null W3SVC, 'Running' wscsvc union all select 18 idse, 'LSTKAG72544' serverName, cast('20180928' as date) [date], CAST('17:09:59' as time) [time], 'Running' SQLBrowser, null W3SVC, null wscsvc ) select min(idse) idse , serverName , [DATE] , [TIME] , min(SQLBrowser) SQLBrowser , min(W3SVC) W3SVC , MIN(wscsvc) wscsvc from Datos group by serverName, [DATE], [TIME];
您需要做的是按某些列分组。在这种情况下,对于
serverName
和Date
,Time
例如,此查询将返回您所期望的结果: