select distinct propertyGroupNo from 表 where attrId in ('0001','0002')

解决方案 »

  1.   

    select distinct propertyGroupNo from 表 where attrId in ('0001','0002')
      

  2.   

    select PropertyGroupNo from 
    表 a inner join
    (select '0001' attrid ,'aaa' attrValue
    union all
    select '0002' attrid ,'bbb' attrValue) b
    on a.attrid=b.attrid and a.attrvalue=b.attrvalue
      

  3.   

    select Max(propertyGroupNo) as propertyGroupNo 
      from 表 where (attrId+attrValue='0001aaa') or (attrId+attrValue)='0002bbb'
      Group by propertyGroupNo
      

  4.   

    上面的CrazyFor朋友的语名有问题,propertyGroupNo=1002的记录也会查出来,应该只查propertyGroupNo=1001的记录啊.请高手仔细分析...
      

  5.   

    CrazyFor(太阳下山明朝依旧爬上来) , up
      

  6.   

    97866(weiLuang)写的有问题么?哦???看半天好象是楼主的问题不大对劲:)
    attrId,attrValue  呵呵,这样的组合按楼主要的条件CRAZYFOR写的没问题
      

  7.   

    select propertyGroupNo from 表 where (attrId= '0001' and attrValue ='aaa') and propertyGroupNo in (select propertyGroupNo from 表 where attrId= '0002' and attrValue ='bbb')
      

  8.   

    属性对必须完全匹配啊,我现在有两对对属性,如果按CrazyFor朋友的方法,匹配一对属性也会查出来的.   难道无法实现吗?
      

  9.   

    楼上要的是AND的条件,上面的语句是OR的条件.
    select PropertyGroupNo from 
    表 a 
    where 
    exists(select 1 from 表 b where a.PropertyGroupNo =b.PropertyGroupNo and b.attrid='0001' and attrVralue='aaa')
    and 
    exists(select 1 from 表 b where a.PropertyGroupNo =b.PropertyGroupNo and b.attrid='0002' and attrVralue='bbb')
      

  10.   

    SQL> select * from test;PROPERTYGROUPNO     ATTRID ATTRVALUE
    --------------- ---------- --------------------
               1001          1 aaa
               1001          2 bbb
               1002          1 aaa
               1002          3 ccc
               1003          4 ddd
               1003          3 ccc已选择6行。SQL> select propertyGroupNo from test where attrId=0001 and attrValue='aaa' or(attrId=0002 and attrV
    alue='ddd');PROPERTYGROUPNO
    ---------------
               1001
               1002SQL> select propertyGroupNo from (select * from test where propertyGroupNo in (select propertyGroupN
    o from test where attrId=0001 and attrValue='aaa')) where attrId=0002 and attrValue='bbb';PROPERTYGROUPNO
    ---------------
               1001SQL>
      

  11.   

    propertyGroupNo    attrId        attrValue  
    1001                          0001            aaa  
    1001                          0002            bbb  
    1002                          0001            aaa  
    1002                          0002            bbb  
    1002                          0003            ccc  
    1003                          0004            ddd  
    1003                          0002            bbb  
    1003                          0003            ccc  如果是上面的记录,1002也会查出来的.
      

  12.   

    对啊,1002符合条件当然会查出来了!!!
    SQL> select propertyGroupNo from (select * from test where propertyGroupNo in
      2  (select propertyGroupNo from test where attrId=0001 and attrValue='aaa'))
      3   where attrId=0002 and attrValue='bbb';PROPERTYGROUPNO
    ---------------
               1001
               1002SQL>
      

  13.   

    propertyGroupNo    attrId        attrValue  
    1001                          0001            aaa  
    1001                          0002            bbb  
    1002                          0001            aaa  
    1002                          0002            bbb  
    1002                          0003            ccc  
    1003                          0004            ddd  
    1003                          0002            bbb  
    1003                          0003            ccc  对于这个源结果集,你要什么样的目标结果集?