商品表:  商品属性表:,我现在像筛选属性符合12英寸和法式的商品,请问这个sql怎么写

解决方案 »

  1.   

    SELECT * FROM `商品表` WHERE `id` IN (SELECT `goods_id` FROM `商品属性表` WHERE `attribute_value` = '12英寸') AND `id` IN (SELECT `goods_id` FROM `商品属性表` WHERE  `attribute_value` = '法式')
      

  2.   

    SELECT * 
    FROM `商品表` 
    where exists (select 1 from 商品属性表 where `attribute_value` = '12英寸')
    and exists (select 1 from 商品属性表 where `attribute_value` = '法式')
      

  3.   


    SELECT * FROM goods WHERE EXISTS (SELECT 1 FROM attribute WHERE attribute_value = '12英寸' AND goods.id=attribute.goods_id)AND EXISTS (SELECT 1 FROM arribute WHERE attribute_value = '法式' AND goods.id=attribute.goods_id) 
      

  4.   

    这个用thinkphp 里的方式怎么写啊!要考虑到分页
      

  5.   

    上面的方法查询出来的不是我要的结果,
    select goods_id from(
        select goods_id,count(goods_id) as num from (
           select distinct goods_id from zxm_shop_goods_attribute where attribute_value = '12英寸'
           union all
           select distinct goods_id from zxm_shop_goods_attribute where attribute_value = '法式' 
        ) as a group by goods_id
    ) as b where num = 2这个查出来的是我要的结果!但是我不知道该怎么用thinkphp写出来,要考虑到分页