日期:2014-05-17  浏览次数:20446 次

【吐血请教】sql查询语句


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

------解决方案--------------------
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
------解决方案--------------------
既然都distinct了,就=3就行了。>3也不可能出现。
------解决方案--------------------
引用:
既然都distinct了,就=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的操作,能不用就别用
 
------解决方案--------------------

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')