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 u.event_id,
u.event_name,
u.start_date,
u.end_date,
u.serv_id,
d.name,
c.client_nm as cli
FROM tevents u
LEFT OUTER JOIN doctors d
ON d.id = u.type
LEFT OUTER JOIN clients c
ON c.id = u.combo_select
WHERE u.start_date between '2018.05.23 06:00:00' and '2018.05.23 21:50:00'
function findAll(str, target) {
let res = [];
let ind = 0;
for(let position = 0; position < str.length; position++) {
if (ind <= position){
ind = str.indexOf(target, position);
if (ind == -1) break;
res.push(ind);
}
}
return res
}
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')