SELECT *, ( IF (`id_group` = 1, 2, 0) + IF (`id_country` = 214, 4, 0) + IF (`id_currency` = 1, 8, 0) + IF (`id_shop` = 1, 16, 0) + IF (`id_customer` = 0, 32, 0)) AS `score` FROM `ps_specific_price` WHERE `id_shop` IN (0, 1) AND `id_currency` IN (0, 1) AND `id_country` IN (0, 214) AND `id_group` IN (0, 1) AND `id_product` = 0 AND `id_customer` = 0 AND `id_product_attribute` = 0 AND `id_cart` = 0 AND (`from` = '0000-00-00 00:00:00' OR '2025-05-08 00:00:00' >= `from`) AND (`to` = '0000-00-00 00:00:00' OR '2025-05-08 00:00:00' <= `to`) AND IF(`from_quantity` > 1, `from_quantity`, 0) <= 1 ORDER BY `id_product_attribute` DESC, `id_cart` DESC, `from_quantity` DESC, `id_specific_price_rule` ASC, `score` DESC, `to` DESC, `from` DESC