如何在分组时,连接多个行数据

ExpandedBlockStart.gif 代码
select   *
FROM  
(
select   top   10  doccode, max (inserttime)  as  inserttime
 
from  saletemplog 
 
where  companyid = ' A13 '
 
and  stcode = ' 002 '
 
and   len (doccode) > 30
 
group   by  doccode
) a
OUTER  APPLY(
    
SELECT  oldcode =   STUFF ( REPLACE ( REPLACE (
            (
                
SELECT  oldcode  FROM  saletemplog
                
WHERE  doccode  =  a.doccode
                
ORDER   BY  inserttime  asc
                
FOR  XML AUTO
            ), 
' <N oldcode=" ' ' , ' ),  ' "/> ' '' ),  1 1 '' )

) b
order   by  inserttime  desc

转载于:https://www.cnblogs.com/sofire/archive/2010/04/22/1717924.html

猜你喜欢

转载自blog.csdn.net/weixin_34221276/article/details/92637999