在SQL中将组放在同一行上

在SQL中将组放在同一行上,sql,sql-server-2008,Sql,Sql Server 2008,我已经创建了一个报告,它返回正确的数据,但是我想知道是否可以在同一行上分组,而不是在多行上分组 举个例子会有帮助 报告目前的产出是: User Count FinishingNextMonth Finishing3Months Finishing6Months Jo Bloggs 5 Person A Jo Bloggs 5 Person B Jo Bloggs 5

我已经创建了一个报告,它返回正确的数据,但是我想知道是否可以在同一行上分组,而不是在多行上分组

举个例子会有帮助

报告目前的产出是:

User       Count    FinishingNextMonth    Finishing3Months    Finishing6Months
Jo Bloggs  5        Person A     
Jo Bloggs  5                              Person B
Jo Bloggs  5                                                  Person C
Jo Bloggs  5                                                  Person D
但我更希望它能输出

User       Count    FinishingNextMonth    Finishing3Months    Finishing6Months
Jo Bloggs  5        Person A              Person B            Person C
Jo Bloggs  5                                                  Person D
这可能吗?如果可能,如何实现

代码如下:

declare @startdate datetime
declare @startdateplusone datetime
declare @startdateplusthree datetime
declare @startdateplussix datetime

set @startdate = '30 jul 2013'
set @startdateplusone = DATEADD(mm,1,@startdate)
set @startdateplusthree = DATEADD(mm,3,@startdate)
set @startdateplussix = DATEADD(mm,6,@startdate)

select 
u.username + ' ' + u.surname as Consultant, 
dbo.GET_CONTRACT_RUNNERS(u.UserId,@startdate) as Runners, 
(select fileas from objects where p.ApplicantId = ObjectID and p.EndDate > @startdate and p.EndDate <= @startdateplusone) as FinishingOneMonth,
(select fileas from objects where p.ApplicantId = ObjectID and p.EndDate > @startdateplusone and p.EndDate <= @startdateplusthree) as FinishingThreeMonths,
(select fileas from objects where p.ApplicantId = ObjectID and p.EndDate > @startdateplusthree and p.enddate <= @startdateplussix) as FinishingSixMonths
from placements p
inner join PlacementConsultants pc on pc.PlacementId = p.PlacementID
inner join Users u on u.UserId = pc.UserId
where p.StartDate < @startdate and p.EndDate > @startdate

group by u.UserName, u.Surname, EndDate, ApplicantId, u.userid
order by u.UserName, u.surname

什么逻辑把人C放在第一行而不是人D?这几乎可以肯定是您应该留给报表应用程序的事情。@gvee它基本上是关于删除空白的。它将被导出到Excel,所以我很高兴保持原样,去掉其中的空白,但更喜欢漂亮的数据:D