www.7671.net > sql判断某个字段重复几次

sql判断某个字段重复几次

1:利用len函数declare @a varchar(20)set @a='adfarghbaaf'select len(@a)- len(replace(@a,'a',''))2:自定义一个函数create function fn_str_times(@str varchar(1000),--原子符串@indexstr varchar(20)--查找的字符)returns intasbegindeclare @

select 字段名, count(字段名) as cnt from 表名 group by 字段名

SELECT DISTINCT 字段 FROM 表 --选出不重复值 select ID from table1 group by ID HAVING COUNT(*)>1--选出重复值

select sum(case when cc=0 then 1 else 0) 0次数,sum(case when cc=1 then 1 else 0) 1次数,sum(case when cc=2 then 1 else 0) 2次数 from tt

用关键字 stinct select stinct 字段 不重复的意思

SELECT [字段],COUNT(0) AS 重复次数 FROM [表名] GROUP BY [字段] HAVING COUNT([字段]) > 1

declare @tt Table (name varchar(100))insert into @tt values ('张三')insert into @tt values ('李四,张三')insert into @tt values ('王五 赵六')insert into @tt values ('赵六')insert into @tt values ('李四')insert into @tt values ('王五,赵六

-- 不保证能对,试试吧!SELECT a,b,c FROM A GROUP BY a,b,c HAVING COUNT(*) 追问: 只要判断 a是否重复就好了 然后这个方法试过了 值不对 追答: select a,b,c,count(a) from A group by a where (select count(a) from A

count函数

用group byselect hrids,paytype,count(*) qty from 表名 group by hrids,paytype having count(*)>1

友情链接:ndxg.net | wkbx.net | zxqt.net | nnpc.net | wwfl.net | 网站地图

All rights reserved Powered by www.7671.net

copyright ©right 2010-2021。
www.7671.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com