日期:2014-05-17 浏览次数:20853 次
SELECT t1.name FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE id=t1.id AND (attr='age' AND Value>24)) AND EXISTS (SELECT 1 FROM t2 WHERE id=t1.id AND (attr='sex' AND Value='boy'));
------解决方案--------------------
with t1 as ( select 1 FId ,'23' value , 'age' attr from dual union all select 1 FId ,'boy' value , 'sex' attr from dual union all select 2 FId ,'26' value , 'age' attr from dual union all select 2 FId ,'boy' value , 'sex' attr from dual ),t2 as ( select 1 Id,'Taylor' Name from dual union all select 2 Id,'Jim' Name from dual ) select t2.Name from t2,(select FId,value,attr,lag(value) over(order by FId) c1,rownum rn from t1) t3 where t2.Id = t3.FId and mod(t3.rn,2)=0 and t3.c1 > 24 name ---------------- 1 Jim
------解决方案--------------------
提供一种方案供楼主比较。已经进行了测试哦。
http://blog.csdn.net/lithor/article/details/7730624