with cte as
(
select
mid,
concat(pid, '(', quantity, ')') as concat_col
from table1
)
select
row_number() over (order by mid) as id,
mid,
string_agg(concat_col, ', ') as final
from cte
group by
mid
with cte as
(
select
mid,
concat(pid, '(', quantity, ')') as concat_col
from table1
)
select
row_number() over (order by mid) as id,
mid,
stuff((
select ',' + concat_col
from cte c1
where c.mid = c1.mid
for XML PATH('')
), 1, 1, '') as final
from cte c
group by
mid
2条答案
按热度按时间k2arahey1#
第一
concate
两列然后做string_agg
. 这是演示。输出:
如果您使用的是旧版本的sql server,请尝试以下操作
omvjsjqw2#