tb_cust cust_name cust_sex cust_reg_nbrselect * from tb_cust where cust_reg_nbr in (select cust_reg_nbr from tb_cust group by cust_reg_nbr having count(*)>=3) 如果表很大,要有索引,否则很慢
if exists(select * from sysObjects where id=object_id(N'tp')) drop table tp create table tp(姓名 varchar(10),性别 char(2),身份证号 varchar(18) ) insert into tp select 'a','m','123' union all select 'b','m','123' union all select 'a','f','123' union all select 'a','m','113' union all select 'a','m','133' select * from tp where 身份证号 in(select 身份证号 from tp group by 身份证号 having count(身份证号)>=3)
select 姓名,性别,身份证号 from 表 group by 身份证号 having count(身份证号)>3
(select cust_reg_nbr from tb_cust group by cust_reg_nbr having count(*)>=3)
如果表很大,要有索引,否则很慢
drop table tp
create table tp(姓名 varchar(10),性别 char(2),身份证号 varchar(18)
)
insert into tp
select 'a','m','123'
union all select 'b','m','123'
union all select 'a','f','123'
union all select 'a','m','113'
union all select 'a','m','133'
select * from tp where 身份证号 in(select 身份证号 from tp
group by 身份证号
having count(身份证号)>=3)
你测试过你的SQL语句了吗?
要负责的哦~~~~~~~~~~~~~ 嘿嘿 !
where 身份证号='2354672784513'
group by 身份证号
having count(*) >3