求个统计话语
求个统计语句
我有个表的备注字段,我想更据备注字段中包含的内容进行统计 group by ,如备注的内容中包含 '%张三%','%李四%'。。。等内容。有没办法用一条语句实现统计
------解决方案--------------------
我有个表的备注字段,我想更据备注字段中包含的内容进行统计 group by ,如备注的内容中包含 '%张三%','%李四%'。。。等内容。有没办法用一条语句实现统计
------解决方案--------------------
- SQL code
select sum(case when patindex('%张三%',备注字段)>0 then 1 else 0 end) 含张三的记录数, sum(case when patindex('%李四%',备注字段)>0 then 1 else 0 end) 含李四的记录数 from 你的表
------解决方案--------------------
- SQL code
select sum(case when col1 like '%张三%' then 1 else 0 end),sum(case when col1 like '%李四%' then 1 else 0 end) from tbl
------解决方案--------------------
- SQL code
select sum(case when patindex('%张三%',备注字段)>0 then 1 else 0 end)as 含张三的记录数, sum(case when patindex('%李四%',备注字段)>0 then 1 else 0 end)as 含李四的记录数 from tab --正解