sql 一列拼接成一行,再分割成列

时间:2023-03-09 22:56:28
sql 一列拼接成一行,再分割成列

sql 一列拼接成一行,再分割成列

原始数据,需要拼接成一行

sql 一列拼接成一行,再分割成列

select * from (select d.*,(SELECT count ([Keyword])FROM [DragonGuoShi].[dbo].[ArticleInfo]where Keyword like'%'+d.Keyword+'%' and [ArticleCreateDate]>'2018-06-10') as Num from (select distinct(Keyword) from( select SUBSTRING( Keyword,number,CHARINDEX(',',Keyword+',',number)-number) as Keyword from( SELECT stuff((SELECT ','+[Keyword] from (SELECT [Keyword]FROM [DragonGuoShi].[dbo].[ArticleInfo]where Keyword!='' and [ArticleCreateDate]>'2018-06-10')a for xml path('')),1,1,'') as Keyword)b ,master..spt_values where
number >=1 and number<=len(Keyword)
and type='p'
and substring(','+Keyword,number,1)=',') c ) d ) e where Num>20 order by Num desc

结果

sql 一列拼接成一行,再分割成列