对表pt进行模糊查询,含有字符串'vt'的spell,列出id,并同时统计个数,id spell
0001 001-vt
0002 002-vt
0003 003-ct
.......................
.......................查询结果返回列表:
4 0001
0002
0003
0022结果为合计4个含有'vt'的id如下句子行不行?
select count(spell),id from pt
where spell like %vt%
0001 001-vt
0002 002-vt
0003 003-ct
.......................
.......................查询结果返回列表:
4 0001
0002
0003
0022结果为合计4个含有'vt'的id如下句子行不行?
select count(spell),id from pt
where spell like %vt%
from #tb where spell like '%vt%'id num
---- -----------
0001 2
0002 2(2 行受影响)
select ID,
sum(case when charindex('vt',spell)>0 then 1 else 0 end)
from pt
group by id