请问这条SQL语句是什么错误? 
select * from aaa where ljth in(select ljth from aaa group by lith having count(*)>1); 
这是从aaa表中选出字段ljth有重复的记录,是正确的.但是:我在这条语句的基础上再加个条件比如说 ljmc ='sss',如何写?
select * from aaa where ljth in(select ljth from aaa group by lith having count(*)>1) and ljmc ='sss';ljmc是表的字段名 ,这样写是错误的.请问如何写?

解决方案 »

  1.   

    试试这种写法select * from aaa a
    where exists(select 1 from aaa b where a.lith=b.lith and a.主键<>b.主键)
    and ljmc ='sss'
      

  2.   

    select * from aaa where ljth in(select ljth from aaa where ljmc ='sss' group by lith having count(*)>1)
    或者
    select * from aaa where ljmc ='sss' and ljth in(select ljth from aaa group by lith having count(*)>1)
    不知道你要那種
      

  3.   

    Try:select * from aaa where ljth in(select ljth from aaa where ljmc ='sss' group by lith having count(*)>1) and ljmc ='sss'
      

  4.   

    having count(ljmc)>1与count(*)>1不是一样的吗? 应该没什么错误?是不是楼主条件没有配好,有空格什么的