$stmt = $mysqli->prepare("UPDATE req
SET balance = balance - ?
WHERE card =? AND code = ? ;");
$stmt->bind_param("sss", $cost, $card, $code);
// set parameters and execute
$cost = $_GET['cost'];
$card = $_POST['card'];
$code = $_POST['code'];
$stmt->execute();
SELECT `p`.`date`, `p`.`sum`, `p`.`type`, `p`.`visit`
FROM `payments` AS `p`
JOIN `visits` AS `v` ON `p`.`visit` = `v`.`id`
WHERE `p`.`date` >= '2022-05-01 00:00:00'
AND `p`.`date` < '2022-05-31 23:59:00'
AND `p`.`type` IN('cash', 'cashless', 'advance')
AND `v`.`office` = 131
SELECT `p`.`date`, `p`.`sum`, `p`.`type`, `p`.`visit`
FROM `payments` AS `p`
WHERE `p`.`date` >= '2022-05-01 00:00:00' AND `p`.`date` < '2022-05-31 23:59:00'
AND `p`.`type` IN('cash', 'cashless', 'advance')
AND EXISTS (SELECT 1 FROM `visits` `v` WHERE `p`.`visit` = `v`.`id` AND `v`.`office` = 131)
SELECT `p`.`date`, `p`.`sum`, `p`.`type`, `p`.`visit`
FROM `payments` AS `p`
JOIN `visits` AS `v` ON `p`.`visit` = `v`.`id`
WHERE `p`.`date` >= '2022-05-01 00:00:00' AND `p`.`date` < '2022-05-31 23:59:00'
AND `p`.`type` = 'cash'
AND `v`.`office` = 131
UNION
SELECT `p`.`date`, `p`.`sum`, `p`.`type`, `p`.`visit`
FROM `payments` AS `p`
JOIN `visits` AS `v` ON `p`.`visit` = `v`.`id`
WHERE `p`.`date` >= '2022-05-01 00:00:00' AND `p`.`date` < '2022-05-31 23:59:00'
AND `p`.`type` = 'cashless'
AND `v`.`office` = 131
UNION
SELECT `p`.`date`, `p`.`sum`, `p`.`type`, `p`.`visit`
FROM `payments` AS `p`
JOIN `visits` AS `v` ON `p`.`visit` = `v`.`id`
WHERE `p`.`date` >= '2022-05-01 00:00:00' AND `p`.`date` < '2022-05-31 23:59:00'
AND `p`.`type` = 'advance'
AND `v`.`office` = 131
select u.name, sum(amount)
from account a
join user u on u.id = a.user_id
join operation o on o.account_id = a.id
where a.currency = 'EUR'
group by u.id, u.name
having sum(amount) > (
select avg(amount)
from account a
join operation o on o.account_id = a.id
where a.currency = 'EUR'
)
select FORMAT(dt, 'yyyy-MM-dd') as d, max(t) as t
from T
group by FORMAT(dt, 'yyyy-MM-dd');
select max_t.*, FORMAT(T.dt, 'HH:mm') hour
from (
select FORMAT(dt, 'yyyy-MM-dd') as date, max(t) as max_t
from T
group by FORMAT(dt, 'yyyy-MM-dd')
) max_t
join T on FORMAT(T.dt, 'yyyy-MM-dd') = max_t.date and T.t = max_t.max_t;
select name, avg(rate) rate
from users u
left join replies r on r.user_id = u.id
group by u.name
order by rate desc
$res = array_reduce(
$data,
function($res, $el) {
// Проверяет, есть ли пара имени бренда в массиве результатов
if (!isset($res[$el['name'].$el['brand']])) {
$res[$el['name'].$el['brand']] = $el;
} elseif (
// если пара имени бренда в массиве результатов проверяет цену
$res[$el['name'].$el['brand']]['price'] > $el['price']
) {
$res[$el['name'].$el['brand']]['price'] = $el['price'];
}
return $res;
},
[]
);
select * from clc
where not exists (select user_id from stat where stat.user_id = clc.user_id);
select clc.*
from clc
left join stat on stat.user_id = clc.user_id
where stat.user_id is null;
SELECT
`tokens`.*
FROM `tokens`
ORDER BY REPLACE(SUBSTRING_INDEX(s_short,';',3), SUBSTRING_INDEX(s_short,';',2), '') DESC;
SELECT
`tokens`.*
FROM `tokens`
ORDER BY SUBSTRING_INDEX(SUBSTRING_INDEX(s_short,';',3),';',-1) DESC;
usort(
$arr,
fn($a, $b) => array_search($a['id'], $ids) <=> array_search($b['id'], $ids)
);
concat('category_id=', t1.id) = t2.category_id;