统计重复出现的次数

 

统计手机号码出现的次数

select B.sjhm , COUNT(*)  from YY043 A, TbInput B  where A.SFZHn=B.Sfzhm  AND  a.订单号=b.Ddbh GROUP BY sjhm having COUNT(*)>1

统计每个状态出现的次数
select distinct zt, count(*) from TbInput where  zt in(25,99,98) and Ddbh='gxyllcx094' group by zt

--查询重复的身份证号码
select sfzhm , COUNT(*) from  YY003 GROUP BY sfzhm having COUNT(*)>1
 
--替换(将4个贫困户替换成一个贫困户)
update b set Dwmc=REPLACE(Dwmc,'(贫困户)(贫困户)(贫困户)(贫困户)','(贫困户)')   from yy021 a, TbInput b where Ddbh='gxylrx041'and a.sfzhm =b.sfzhm
 
--左连接查询
select * from 表1 left join 表2 on 表1.列名=表2.列名
 
--截取身份证号码
update A002 set Csrq=SUBSTRING(sfzhm,7,8) where (Csrq is null or Csrq='') and len(sfzhm)=18

--原始信息截取前面的18位
select LEFT(ysxx,18) from TbInput where Ddbh='ahfyyz072'
 
--查询身份证是否有汉字
select * from A001 where ascii(sfzhm)>127 查出包含汉字
 
--查询地址里面有没有特殊字符的
select id,sfzhm,Hjszd from TbInput where ddbh='ahfyjs001' and Zt=25 and Hjszd like '%[^吖-座0-9A-Za-z-]%' and Hjszd not  like '%[(-)-#]%'
 
--月度统计
select * from (select p.Xmbh,p.Xmmc,DAY(t.czsj) czrq,COUNT(0) nCount from TbInput t with (nolock),TbProject p with (nolock) 
where  YEAR(t.CZSJ)=2019 AND month(t.CZSJ)=8 AND t.ZT=25 and t.Xmbh=p.Xmbh group by p.Xmbh,p.Xmmc,DAY(t.czsj)) AS t1 PIVOT (SUM(nCount) FOR czrq IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31],[32])) AS t2
order by xmmc
 
 
posted @ 2020-10-20 14:16  我们一起爱一挨一起哀  阅读(332)  评论(0编辑  收藏  举报