如题,即如何知道记录"1 a  10" 在字段city中,a是重复的(即有多个a)?
     
              id   city  people
              1     a     10
              2     a     30
              3     a     20
              4     b     50
              5     b     10
              6     b     20

解决方案 »

  1.   


    select city,count(1) from  表 group by city having count(city)>1
      

  2.   

    select city,count(*) from  table group by city having count(*) >1
      

  3.   

    sele city, count(city) from table group by city 
      

  4.   

    select count(*) from tb where city='a'
      

  5.   

    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 行受影响)*/
      

  6.   

    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'