日期:2014-05-16  浏览次数:20675 次

求助一条sql。大家帮忙看看。
id 商品id 参数id  
1 35 1
2 35 2
3 38 1
4 38 3
5 37 1


以参数id为条件查询商品id,如输入1查询35 37 38 再输入2 需要把1条件累加 查询出 35
 本人想法是 自连查询, 请问有什么效率更高的方法,因为如果查询条件过多,会导致自连N次。


------解决方案--------------------
select *
from table1 t
where 参数id = 2
and exists (select 1 from table1 where 参数id = 1)
------解决方案--------------------
探讨
引用:
id 商品id 参数id
1 35 1
2 35 2
3 38 1
4 38 3
5 37 1


以参数id为条件查询商品id,如输入……

------解决方案--------------------
select proid from table t1 where id = 1 join (select proid from table where id = 2) t2 on(t1.proid = t2.id);给点分吧。。。苦逼得我