,
一个表里的数据是这样的,,我想要搜索attribute_id = 2 attribute_group_id = 2 ,attribute_id = 6 attribute_group_id = 6 的 product_id,即attribute_id = 2 attribute_group_id = 2, 而且attribute_id = 6 attribute_group_id = 6

解决方案 »

  1.   

    select product_id from table where (attribute_id = 2 and attribute_group_id = 2) or (attribute_id = 6 and attribute_group_id = 6)
      

  2.   

    select distinct(product_id) from table where product_id in(select product_id from table attribute_id = 2 and attribute_group_id = 2) and poduct_id in(select product_id from table attribute_id = 6 and attribute_group_id = 6)
      

  3.   

    select * from table where product_id in(select product_id from table attribute_id = 2 and attribute_group_id = 2) and poduct_id in(select product_id from table attribute_id = 6 and attribute_group_id = 6) group by product_id
      

  4.   

    只能建议给product_id建索引了,查询效率这个我说不清楚。