我有一个SQL查询:
SELECT `shop_items`.*
FROM `shop_items`
LEFT OUTER JOIN `shop_item_properties` ON `shop_items`.`shop_id` = `shop_item_properties`.`shop_id`
LEFT OUTER JOIN `property_value_ints` ON `shop_items`.`id` = `property_value_ints`.`entity_id` AND `shop_item_properties`.`property_id` = property_value_ints.property_id
WHERE `shop_group_id` = '835'
AND
(
(
`shop_item_properties`.`property_id` = '565'
AND
`property_value_ints`.`value` >= 1950
AND
`property_value_ints`.`value` <= '2011'
OR
`shop_item_properties`.`property_id` = '566'
AND
`property_value_ints`.`value` >= '2011'
AND
`property_value_ints`.`value` <= 2016
)
OR
(
`shop_item_properties`.`property_id` = '565'
AND
`property_value_ints`.`value` = 0
OR
`shop_item_properties`.`property_id` = '566'
AND
`property_value_ints`.`value` <= '2011'
)
)
AND `shop_items`.`deleted` = 0
GROUP BY `shop_items`.`id`
HAVING COUNT(`shop_item_properties`.`id`) = 2
我想要什么。物品有两个属性:多年的问题,例如: 1950-2010(财产ID为565 = 1950,财产566 = 2010)或2010 -...(财产565 = 0,财产566 = 2010.我知道这是一个错误的决定,但我没有发明)所以,我和#39;正在寻找在特定年份发行的物品
请帮助我更改WHERE shop_group_id = '835'
和AND shop_items.deleted = 0
之间的查询,因为右边的其余部分。
答案 0 :(得分:0)
类似的东西:
UNION