← All posts tagged говнокод

Кусок проекта:
SELECT
t1.*,
(SELECT
SUM(price)
FROM menu_prices AS t2
WHERE id IN(SELECT
id
FROM menu_prices AS t3
WHERE menu_item_id = t1.id
AND price = (SELECT
MIN(t4.price)
FROM menu_prices AS t4
WHERE t4.price_group_id = t3.price_group_id AND t4.menu_item_id = t3.menu_item_id)
GROUP BY price_group_id)) AS min_price,
(SELECT
SUM(price)
FROM menu_prices AS t2
WHERE id IN(SELECT
id
FROM menu_prices AS t3
WHERE menu_item_id = t1.id
AND price = (SELECT
MAX(t4.price)
FROM menu_prices AS t4
WHERE t4.price_group_id = t3.price_group_id AND t4.menu_item_id = t3.menu_item_id)
GROUP BY price_group_id)) AS max_price
FROM `menu_items` AS t1
WHERE (t1.restaurant_id = 1)
AND (t1.group_id = 3);