表单是这样 no name age 
          1  ll   18
          2  mm   18
          3  kk   17
          4  qq   16
我想查一下重复的age即显示1  ll   18
                       2  mm   18
可是我用这样的语句应该没错啊
select*
from table
where age in
(select age
 from table 
 group by age
 having count(age)=2)
可是总是报错,ERROR 1064 
             

解决方案 »

  1.   

    如果不用子查询呢,who know
      

  2.   

    你的mYSQL版本是多少?
    另外建议贴出你实际的语句。否则table是关键字 `table`
      

  3.   

    我觉得表名用table出错的可能性更大一点,换个表名看看
      

  4.   

    select * from table a
    inner join 
    (select age,max(no) as ma from table group by age having count(age)=2)  b
    on a.age=b.age and a.no=b.ma
      

  5.   

    or
    select a.no,a.name,a.age from test a 
    left join test b on a.age=b.age and a.no>=b.no
    group by a.no,a.name,a.age
    having count(b.age)>=2
      

  6.   


    对。版本不支持。没什么好办法。只能这样处理了select a.no,a.name,a.age 
    from tableName a inner join tableName b on a.age=b.age
    group by a.no,a.name,a.age 
    having count(*)>1
      

  7.   


    select* 
    from table group by age having count(*)>2