1.原题: https://leetcode.com/problems/defanging-an-ip-address/ 这道题本身很简单, Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period "." with "[.]". 翻译就是,给出一个ipv4地址,把这个地址中的“.
declare @test table( name varchar(10)) insert into @test values('a') insert into @test values('b') insert into @test values('c') insert into @test values('d') SELECT * FROM @test select distinct (select cast(name AS varchar(2))+','from @test for xml
create table #test ( id int not null, memeo int not null ) ,) ,) ,) )) ,,'') drop table #test 总结: 格式: SELECT STUFF((SELECT ','+字段 FROM 表名 for xml path('')),1,1,'')