mysql group by 重复_mysql – 使用GROUP BY删除重复项的查询
id_specific_price id_product
-------------------------------
1 2
2 2
3 2
4 3
5 3
6 3
7 3
需要刪除重復項,預期結果:
id_specific_price id_product
-------------------------------
3 2
7 3
SELECT *
FROM ps_specific_price
WHERE id_specific_price NOT IN
(SELECT MAX(id_specific_price)
FROM ps_specific_price
GROUP BY id_product)
工作,但
DELETE FROM ps_specific_price
WHERE id_specific_price NOT IN
(SELECT MAX(id_specific_price)
FROM ps_specific_price
GROUP BY id_product)
才不是.有很多例子可以解決這個問題,但由于某種原因,我無法適應它.我相信它是GROUP BY.例如:
DELETE FROM ps_specific_price
WHERE id_specific_price NOT IN
(SELECT MAX(p.id_specific_price)
FROM (SELECT * FROM ps_specific_price ) as p)
GROUP BY id_product
我在哪里錯了?
總結
以上是生活随笔為你收集整理的mysql group by 重复_mysql – 使用GROUP BY删除重复项的查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lua excel to mysql_在
- 下一篇: mysql vacuum_Postgre