当前位置: 代码迷 >> Sql Server >> 统计个A数。解决方法
  详细解决方案

统计个A数。解决方法

热度:36   发布时间:2016-04-24 09:51:23.0
统计个A数。
table
ID  A(string)
1   252 
2   52,53,54
3   52,53,54
4   52,53,54
5   52,53,54,55

select count(*) from table  where  a like '%'+convert(nvarchar(50),table.a)+'%'

这样的话,肯定不对。 52 会统计为 5个。

------解决思路----------------------
不知道你的sql中a 是什么意思

declare @i int
set @i=52
select count(*) from tablename where ','+convert(varchar(50),@i)+',' like '%,'+A+',%'
------解决思路----------------------
如果你是要统计A里面有多少个数的话用这个

select ID,len(a)-len(REPLACE(a,',',''))+1 from tablename 
  相关解决方案