如何使这个eav查询水平

时间:2015-06-25 15:04:52

标签: mysql entity-attribute-value

我想从下表格记录中选择(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'))
      ) 

0 个答案:

没有答案