比如一串数字14,23,64,23,14,20,30
其中14重复两次,23重复两次,其余没有重复。
=================================
declare @sql varchar(1000)
declare @str varchar(100)
set @str='14,23,64,23,14,20,30'
select @sql='select col,count(1) as c from (select '
+replace(@str,',',' as col union all select')
+') b group by col order by c desc '
print (@sql)
exec (@sql)
/*
col c
----------- -----------
14 2
23 2
30 1
20 1
64 1
*/