select city,count(1) from 表 group by city having count(city)>1
select city,count(*) from table group by city having count(*) >1
sele city, count(city) from table group by city
select count(*) from tb where city='a'
create table tb(id int,city varchar(10),people int) insert into tb select 1,'a',10 insert into tb select 2,'a',30 insert into tb select 3,'a',20 insert into tb select 4,'b',50 insert into tb select 5,'b',10 insert into tb select 6,'b',20 select count(*) from tb where city='a' go drop table tb /* ----------- 3(1 行受影响)*/
create table aa(id int ,city varchar(1),people int) insert into aa select 1 ,'a' ,10 union all select 2, 'a', 30 union all select 3, 'a', 20 union all select 4, 'b', 50 union all select 5, 'b', 10 union all select 6, 'b', 20select count(city) from aa where city='a'
select city,count(1) from 表 group by city having count(city)>1
insert into tb select 1,'a',10
insert into tb select 2,'a',30
insert into tb select 3,'a',20
insert into tb select 4,'b',50
insert into tb select 5,'b',10
insert into tb select 6,'b',20
select count(*) from tb where city='a'
go
drop table tb
/*
-----------
3(1 行受影响)*/
insert into aa
select 1 ,'a' ,10 union all
select 2, 'a', 30 union all
select 3, 'a', 20 union all
select 4, 'b', 50 union all
select 5, 'b', 10 union all
select 6, 'b', 20select count(city) from aa where city='a'