|
create table a (aname varchar (100))
declare @str varchar (100), @ T_sql varchar (8000)
set @str = 'aaaa, bbbb, cccc, dddd'
set @ T_sql = 'insert a select' ''
set @ T_sql = @ T_sql + replace (@str, ',', '' 'union all select' '') + '' ''
--select @T_sql
exec (@T_sql)
--select * from a
declare @t table (id int identity (1,1), keyword varchar (100))
insert @t select 'aaaa, bbbb, cccc, dddd'
union all select 'aaaa, bbbb'
union all select 'aaaa'
union all select 'aaaa, bbbb, cccc'
union all select 'eeee, ffff'
--select * from @t
--select keyword, a. * from a right join @t b on charindex (',' + a.aname + ',', ',' + b.keyword + ',')> 0
select keyword from a inner join @t b on charindex (',' + a.aname + ',', ',' + b.keyword + ',')> 0 group by keyword order by count (*) desc
drop table a
Yesterday, I worked over half an hour for your question. At that time, I thought about it a bit. I wanted to retrieve the data that does not exist in the query condition association table, such as a, b, c, d; I remembered thinking about it on the road! Hey, half an hour wasted |
|