以下代码:
select(
select m.Code + ' ' + cast(m.Completed as varchar(max)) + ' '+ cast(ol.Billed as varchar(max)) + ' ' + cast(m.Delete as varchar (max))
from matterdetails as m
full join officeledger as ol on ol.id=m.id
order by ol.Billed desc
for xml path(''))
返回结果
Code Completed Billed Deleted
-------- ----------- ----------- -----------
HK168/03 Mar 30 2012 Aug 17 2011 Mar 30 2012
HK168/03 Mar 30 2012 Feb 24 2011 Mar 30 2012
HK168/03 Mar 30 2012 Dec 23 2010 Mar 30 2012
FT080/03 Apr 4 2012 Mar 29 2012 Apr 4 2012
FT080/03 Apr 4 2012 Feb 9 2012 Apr 4 2012
FT080/03 Apr 4 2012 Oct 20 2011 Apr 4 2012
etc.
而我需要结果
Code Completed Billed Deleted
-------- ----------- ----------- -----------
HK168/03 Mar 30 2012 Aug 17 2011 Mar 30 2012
FT080/03 Apr 4 2012 Mar 29 2012 Apr 4 2012
etc.
我知道我必须在select top 1
某处插入以限制ol.Billed
结果,但我不确定在哪里。任何建议都会很棒。