我有很多重复的数据,我试图只更新数量最高的行,按多个列分组。我试过但没用。任何帮助都将不胜感激。谢谢
UPDATE `polls` AS `p1`
INNER JOIN (
SELECT *
FROM `polls`
GROUP BY `server_id`, `product_id`, `poll_date`
ORDER BY max(quantity)
HAVING COUNT(*) > 1
) AS `p2`
ON `p2`.`server_id` = `p1`.`server_id`
AND `p2`.`product_id` = `p1`.`product_id`
AND `p2`.`poll_date` = `p1`.`poll_date`
SET `p1`.`updated_by` = 'admin';
最佳答案
试试这个
....
INNER JOIN (
SELECT * , max(quantity)
FROM `polls`
GROUP BY `server_id`, `product_id`
ORDER BY max(quantity) desc
)
....
关于mysql - 需要帮助从重复数据中查询最大值,按多列分组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21940864/