[Solved] SQL query needed for a complex structure


Without a better understanding of the rules and data this is the best I can come up with. It is based on your first array example –

SELECT `r`.*
FROM `rule_attribute_value` `rav`
INNER JOIN `rule` `r`
    ON `rav`.`rule_id` = `r`.`rule_id`
INNER JOIN `rule_attribute` `ra`
    ON `rav`.`attribute_id` = `ra`.`attribute_id`
WHERE
    (`rav`.`store_id` = 0 AND `ra`.`attribute_code` = 'customer'        AND `rav`.`value` = 2) OR
    (`rav`.`store_id` = 0 AND `ra`.`attribute_code` = 'customer_group'  AND `rav`.`value` = 1) OR
    (`rav`.`store_id` = 0 AND `ra`.`attribute_code` = 'country'         AND `rav`.`value` = 15) OR
    (`rav`.`store_id` = 0 AND `ra`.`attribute_code` = 'subdivision_one' AND `rav`.`value` = 224)
GROUP BY `r`.`rule_id`
HAVING COUNT(DISTINCT `rav`.`attribute_id`) = 4 /* 4 IS THE NUMBER OF ATTRIBUTES BEING QUERIED */
ORDER BY `r`.`position` ASC
LIMIT 1;

1

solved SQL query needed for a complex structure