SELECT * FROM `商品表` WHERE `id` IN (SELECT `goods_id` FROM `商品属性表` WHERE `attribute_value` = '12英寸') AND `id` IN (SELECT `goods_id` FROM `商品属性表` WHERE `attribute_value` = '法式')
SELECT * FROM `商品表` where exists (select 1 from 商品属性表 where `attribute_value` = '12英寸') and exists (select 1 from 商品属性表 where `attribute_value` = '法式')
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)
这个用thinkphp 里的方式怎么写啊!要考虑到分页
上面的方法查询出来的不是我要的结果, 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写出来,要考虑到分页
FROM `商品表`
where exists (select 1 from 商品属性表 where `attribute_value` = '12英寸')
and exists (select 1 from 商品属性表 where `attribute_value` = '法式')
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)
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写出来,要考虑到分页