-- 红球遗漏次数分析图 select a.beforeterm,a.leaktimes, stuff( (select ','+cast(ballnum as varchar(max)) from [Lottory].[dbo].[RedBall] b where a.leaktimes = b.leaktimes and a.beforeterm = b.beforeterm for xml path('')) ,1,1,'') balls from ( select beforeterm, leaktimes from [Lottory].[dbo].[RedBall] group by beforeterm, leaktimes ) a -- 篮球遗漏次数分析图 select a.beforeterm,a.leaktimes, stuff( (select ','+cast(ballnum as varchar(max)) from [Lottory].[dbo].[BlueBall] b where a.leaktimes = b.leaktimes and a.beforeterm = b.beforeterm for xml path('')) ,1,1,'') balls from ( select beforeterm, leaktimes from [Lottory].[dbo].[BlueBall] group by beforeterm, leaktimes ) a