一条sql。大家帮忙看看

求助一条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);给点分吧。。。苦逼得我

一条sql。大家帮忙看看

相关文章:

你感兴趣的文章:

标签云: