DB: MySqlProblem:create table aaa(
    id int primary key,
    phone varchar(100),
    name varchar(50)
)insert into aaa values(000101,'111','jackie');
insert into aaa values(000102,'222','milk');
insert into aaa values(000103,'111','lucy');
insert into aaa values(000104,'111','mechelle');
insert into aaa values(000105,'222','tom');
insert into aaa values(000106,'333','roy');查找出phone列有重复的值,即count(phone)>=2的值列出来Required Result:
phone   num
111     3
222     2请高手解答,在线等,谢谢

解决方案 »

  1.   

    select phone,
           count(*)num
    from aaa
    group by phone
    having count(*)>=2
      

  2.   

    create table aaa(
      id int primary key,
      phone varchar(100),
      name varchar(50)
    )insert into aaa values(000101,'111','jackie');
    insert into aaa values(000102,'222','milk');
    insert into aaa values(000103,'111','lucy');
    insert into aaa values(000104,'111','mechelle');
    insert into aaa values(000105,'222','tom');
    insert into aaa values(000106,'333','roy');
    select phone,
           count(*)num
    from aaa
    group by phone
    having count(*)>=2
    drop table aaa
    /*
    phone                                                                                                num
    ---------------------------------------------------------------------------------------------------- -----------
    111                                                                                                  3
    222                                                                                                  2(2 個資料列受到影響)
    */
      

  3.   

    select phone,count(phone) as num from aaa
    group by phone
    having count(phone)>=2
      

  4.   

    select phone, count(*)num from aaa
    group by phone
    having count(phone)>=2