a (id, name ,birthdate)
如何查找一个表里不同用户有相同的出生日期的用户

解决方案 »

  1.   

    select distinct a.id,a.name,a.birthdate
    from a t1, a t2
    where t1.birthdate=t2.birthdate
    and t1.id != t2.id
    order by a.birthdate
      

  2.   

    i use this
    select * from a
    where birthday in (
    select  birthday  from  a  group  by  birthday  having  count(birthday) > 1) order by birthday
      

  3.   

    select a.* from tt a
    inner join
    (select birthdate from tt group by birthdate having count(*)>=2) b
    on a.birthdate=b.birthdate
      

  4.   

    select 
      name,
      birthdate
    from
      a
    group by 
      name,
      birthdate
    having
      count(*)>1
      

  5.   

    select distinct a.id,a.name,a.birthdate
    from a t1, a t2
    where t1.birthdate=t2.birthdate
    and t1.id != t2.id
    order by a.birthdate

    select a.* from tt a 
    inner join 
    (select birthdate from tt group by birthdate having count(*)>=2) b 
    on a.birthdate=b.birthdate
    数据不完全一致 
    后者总是多几条  (后者总是有几个只有1条 不重复记录的结果)
    反复测试 发现 , 如何调整后者 (后者性能远远大于前者)