我想从下表格记录中选择(property_id=18 and property_value=78) and (property_id=19 and property_value=113)
此表中的结果记录id = 12
。
Link表格的图像。
这是我的MySQL查询:
SELECT DISTINCT `Product`.* , ProductMeta.property_id, ProductMeta.property_value
FROM `shop_products` AS `Product`
LEFT JOIN `shop_categories` AS `Category` ON (`Product`.`category_id` = `Category`.`id`)
LEFT JOIN `shop_product_metas` AS `ProductMeta` ON (`Product`.`id` = `ProductMeta`.`product_id`)
WHERE
`Product`.`category_id` = (26)
AND
(`Product`.`price` * (1 - (`Product`.`off`/100)) ) >= '100'
AND
(`Product`.`price` * (1 - (`Product`.`off`/100)) ) <= '5000000'
AND
(
(
((`ProductMeta`.`property_id` = 18) AND (`ProductMeta`.`property_value` = '77'))
OR
((`ProductMeta`.`property_id` = 18) AND (`ProductMeta`.`property_value` = '78'))
)
AND
((`ProductMeta`.`property_id` = 19) AND (`ProductMeta`.`property_value` = '113'))
)