SELECT product_status.*,
product.*,
pay.*,
((SELECT SUM(pay.summa)
FROM pay
WHERE pay.pay_id = product.paysystem_id)/product.price)*100 AS 'percent'
FROM product_status
JOIN product
ON product.status_id = product_status.id
JOIN pay
ON pay.pay_id = product.paysystem_id
SELECT to_t.name, to_t.id, to_t2.name, to_t2.id
FROM to_team_games to_t_g
LEFT JOIN to_teams to_t on to_t_g.team_id_1 = to_t.id
LEFT JOIN to_teams to_t2 on to_t_g.team_id_2 = to_t2.id
WHERE to_t_g.id= 1
SELECT pd.product_id,
d.name,
d.discount_percent,
d.discount_amount
FROM s_products_discount pd
LEFT JOIN s_discounts d
ON d.id = pd.discount_id
LEFT JOIN (SELECT MAX(d.priority) as max_priority
FROM s_discounts dd
WHERE dd.id = pd.discount_id
AND dd.visible = 1
AND dd.date_from <= '2018-05-05'
AND dd.date_to >= '2018-05-05') pp
ON pp.max_priority = d.priority
WHERE pd.product_id IN ('41987', '41988', '41989', '41990', '41991', '41992', '41993', '41994')