INSERT INTO `items` (`id`, `id_shop`, `name`, `description`, ...)
SELECT `id`, `id_shop`, `name` AS `new_name`, `description` AS `new_description`, ...
FROM `new_items`
ON DUPLICATE KEY UPDATE `name` = `new_name`, `description` = `new_description`, ...
SELECT `z`.`id`,
`ra`.`count` AS `acount`, `ra`.`rate` AS `asum`,
`rc`.`count` AS `ccount`, `rc`.`rate` AS `csum`
FROM `zav` AS `z`
LEFT JOIN (
SELECT COUNT(*) AS `count`, sum(`rate`) AS `rate`
FROM `rating`
WHERE `type` = 'a'
GROUP BY `id`
) AS `ra` ON `ra`.`id` = `z`.`id`
LEFT JOIN (
SELECT COUNT(*) AS `count`, sum(`rate`) AS `rate`
FROM `rating`
WHERE `type` = 'c'
GROUP BY `id`
) AS `rc` ON `rc`.`id` = `z`.`id`
WHERE `z`.`city` = 'spb' AND `z`.`closedzav` = '0'