And here's one that does it all (updated SQL Fiddle);with base as ( select m.label, d.id, dense_rank() over (order by d.id) rk from dimension1 d join dimensionmember m on m.dimensionid = d.id where d.label in ('sex','Employment Type','Contract Type')), cte as ( select cast(label as varchar(max)) list, rk from base where rk=1union all select cast(cte.list+','+base.label as varchar(max)), base.rk from cte join base on base.rk=cte.rk+1) select list from cte where rk=(select max(rk) from base) 这篇关于交叉连接同一表中的N组行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS! 05-22 12:46