求助,查询 (Attr = Length 并且 Value = 6.00000) 并且 (Attr = DIAM 并且 Value = 0.250000) 并且 (Attr = TIP 并且 Value = FLAT) 的 ID_ITEM,我感觉这玩意爆难,要吐血了.求教大神解答,谢过先。不清楚的话尽管问哈。sql高级查询

解决方案 »

  1.   

    select id_item from (select distinct * from 表)a
    where (Attr = Length and Value = 6.00000) or (Attr = DIAM and Value = 0.250000) or (Attr = TIP and Value = FLAT)
    group by id_item
    having count(1)>=3
      

  2.   

    既然都distinct了,就=3就行了。>3也不可能出现。
      

  3.   

    SELECT DISTINCT ID_ITEM 
    FROM TABLENAME
    (Attr = 'Length' AND Value = 6.00000) 
    OR (Attr = 'DIAM' OR Value = 0.250000) 
    OR (Attr = 'TIP' AND Value = 'FLAT')--算是基础SQL,不需要GROUP BY也行的,GROUP BY是比较消耗CPU的操作,能不用就别用
     
      

  4.   


    select distinct ID_ITEM
     from [表名]
     where (Attr='Length' and Value='6.00000')
        or (Attr='DIAM' and Value='0.250000') 
        or (Attr='TIP' and Value='FLAT')