select count(id) from table where type='01' and type <>'08'
(id=2 or id =3) group by id

解决方案 »

  1.   

    补充一点:
    (id=2 or id =3)不能当作条件使用
    我的意思是
    id为2,3的记录正好满足我的条件
      

  2.   

    select id from (
    select * from tb where type in ('01','08')
    ) t group by id having count(*)=1;
      

  3.   

    如果我换一种需求:找出type类型有01,也有08的这些id 
      

  4.   

    终于搞出来了,其实很简单...
    select  count(*) from table where type not in  ('08') 
    and id in(
    select  id from  table 
    where type='01')
    谢谢大家
      

  5.   

    楼上:
    请问你的语句和下面的语句有什么区别:
    select  count(*) from table where type = '01';
      

  6.   

    bluesky1980(sugar) 你还缺少了对ID进行分组select count(id) from (select id,sum(decode(type,'01',1,'08',-99999999,0))as sumvalue from table group by id) a where a.sumvalue>0如果type是'01',置1,如果是'08',置-99999999,其他则置0,一般情况下相同ID的记录条数不会有99999999条,把所有记录的该字段求和,如果有'08'则肯定为负,如果没有‘01’则肯定小于等于0。
    我的方法比较笨,但应该符合楼主的条件,我感觉我上面的各个回复好象都实现不了楼主的目的。
    如果要实现“如果我换一种需求:找出type类型有01,也有08的这些id ”那么如下
    select id from (
    select * from tb where type in ('01','08')
    ) t group by id having count(*)>=1;
    如果要实现“如果我换一种需求:找出type类型只有01或者只有08的这些id ”那么如下
    select id from (
    select * from tb where type in ('01','08')
    ) t group by id having count(*)=1;