UPDATE `trade_log` AS `tl`
JOIN `users` AS `u` ON `tl`.`tradeId` = ? AND `tl`.`status` = 'send'
AND `u`.`steam_id` = `tl`.`steamid_other`
SET `tl`.`status` = 'success', `u`.`balance` = `u`.`balance` + `tl`.`sum`
SELECT `steamid_other`, `sum`
FROM `trade_log`
WHERE `tradeId` = ? AND `status` = 'success'
SELECT `b`.`*`, `i`.`count`
FROM (
SELECT `ib`.`id_brand` AS `brand`, COUNT(*) AS `count`
FROM `item_brand` AS `ib`
JOIN `item` AS `i` ON `i`.`enabled` = 1
AND `i`.`id_category` IN (21,317,318)
AND `i`.`id` = `ib`.`id_item`
GROUP BY `ib`.`id_brand`
) AS `i`
JOIN `brand` AS `b` ON `b`.`id` = `i`.`id_brand`
ORDER BY `i`.`count` DESC
SELECT `b`.`id`, `b`.`title`, `b`.`description`, `b`.`public`,
(SELECT COUNT(*) FROM `likes` WHERE `boycottid` = :boycot_id) AS `likes`,
(SELECT COUNT(*) FROM `dislikes` WHERE `boycottid` = :boycot_id) AS `dislikes`,
(SELECT COUNT(*) FROM `subscriptions` WHERE `boycottid` = :boycot_id) AS `subscriptions`
FROM (
SELECT `id`, `title`, `description`, `public` FROM `boycotts` WHERE `id` = :boycot_id
) AS `b`
SELECT `u`.`nick`, IFNULL(`tc`.`count`, 0) AS `comments`,
IFNULL(`fp`.`count`, 0) AS `posts`,
IFNULL(`l`.`count`, 0) AS `likes`
FROM `users` AS `u`
LEFT JOIN (
SELECT `sender_id`, COUNT(*) AS `count`
FROM `thread_comments` GROUP BY `sender_id`
) AS `tc` ON `tc`.`sender_id` = `u`.`id`
LEFT JOIN (
SELECT `sender_id`, COUNT(*) AS `count`
FROM `forum_posts` GROUP BY `sender_id`
) AS `fp` ON `fp`.`sender_id` = `u`.`id`
LEFT JOIN (
SELECT `owner_id`, COUNT(*) AS `count`
FROM `likes` GROUP BY `owner_id`
) AS `l` ON `l`.`owner_id` = `u`.`id`
ORDER BY `tc`.`count` DESC, `u`.`nick` ASC
LIMIT 15
SELECT `t1`.`code`, `t1`.`name`, `t1`.`max_int1`, `t2`.`name`, `t2`.`max_int2`
FROM (
SELECT `t`.`name` AS `name`, `t`.`code` AS `code`, `t`.`int1` AS `max_int1`
FROM (
SELECT `code`, MAX(`int1`) AS `int1`
FROM `table` WHERE `city`= :city GROUP BY `code`
) AS `m`
JOIN `table` AS `t` ON `t`.`city` = :city AND `t`.`code` = `m`.`code`
AND `t`.`int1` = `m`.`int1`
) AS `t1`
JOIN (
SELECT `t`.`name` AS `name`, `t`.`code` AS `code`, `t`.`int2` AS `max_int2`
FROM (
SELECT `code`, MAX(`int2`) AS `int2`
FROM `table` WHERE `city`= :city GROUP BY `code`
) AS `m`
JOIN `table` AS `t` ON `t`.`city` = :city AND `t`.`code` = `m`.`code`
AND `t`.`int2` = `m`.`int2`
) AS `t2` ON `t1`.`code` = `t2`.`code`