当前位置: 代码迷 >> Sql Server >> 求个统计话语
  详细解决方案

求个统计话语

热度:47   发布时间:2016-04-27 11:21:27.0
求个统计语句
我有个表的备注字段,我想更据备注字段中包含的内容进行统计 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--正解
  相关解决方案