UPDATE users u1
CROSS JOIN users u2
SET u1.amount = u1.amount - $summa,
u2.amount = u2.amount + $summa
WHERE u1.id = $client
AND u2.id = $shop;
SELECT t1.*
FROM table t1
WHERE EXISTS ( SELECT NULL
FROM table t2
WHERE t1.id <> t2.id -- выражение первичного ключа
AND t1.column = t2.column -- для всех полей, кроме первичного ключа
DELETE
FROM table t1
WHERE EXISTS ( SELECT NULL
FROM table t2
WHERE t1.id > t2.id -- оставить только запись с минимальным ID
AND t1.column = t2.column
SELECT value,
SUM(value = val1) total_1,
SUM(value = val2) total_2
FROM ( SELECT val1 value FROM test
UNION
SELECT val2 FROM test ) total
CROSS JOIN test
GROUP BY value
ORDER BY value;
SELECT 500 queue, operator, os.avg_os, ss.avg_ss
FROM ( SELECT operator,AVG(valuation) avg_os
FROM oper_survey
WHERE queue = '500' AND `date` BETWEEN '2021-06-01' AND '2021-06-16'
GROUP BY operator ) os
JOIN ( SELECT operator, AVG(valuation) avg_ss
FROM service_survey
WHERE queue = '500' AND `date` BETWEEN '2021-06-01' AND '2021-06-16'
GROUP BY operator ) ss USING (operator)
SELECT 500 queue, operator, COALESCE(os.avg_os, 0) avg_os, COALESCE(ss.avg_ss, 0) avg_ss
FROM ( SELECT operator FROM oper_survey WHERE queue = '500'
UNION
SELECT operator FROM service_survey WHERE queue = '500' ) op
LEFT JOIN ( SELECT operator,AVG(valuation) avg_os
FROM oper_survey
WHERE queue = '500' AND `date` BETWEEN '2021-06-01' AND '2021-06-16'
GROUP BY operator ) os USING (operator)
LEFT JOIN ( SELECT operator, AVG(valuation) avg_ss
FROM service_survey
WHERE queue = '500' AND `date` BETWEEN '2021-06-01' AND '2021-06-16'
GROUP BY operator ) ss USING (operator)
SELECT users.name AS username,
count(orders.id) AS orders_count
FROM users
JOIN orders ON orders.user_id=users.id
GROUP BY users.name
Правильно ли понимаю, что в случае отказа слейва на какое-то условное кол-во времени за которое mysql-bin.log заротейтится при достижении условных 100М, то при восстановлении слейв сервера, данные, которые находятся уже в архивном логе не будут записаны?
SELECT TOP 500 *
FROM [table]
WHERE NOT EXISTS ( SELECT NULL
FROM [Entities]
WHERE [column] = '2'
AND [table1].[Id] = [ClientTableId] )
восстановить файл после удаления из корзины
удалил txt файлик с рабочего стола