我有一个 MySQL 表,其摘录如下:
我需要保留 assoc_case、文档和参与者相同的每一行的最新行。例如,我只想将第 136 行保留在第 133-136 行之外。
我正在研究这个,但似乎无法适应我的需要:
SELECT
id,
assoc_case,
participant,
document,
MAX(created)
FROM
`table`
GROUP BY
created,
assoc_case,
participant,
document
最佳答案
在 MySQL 中,您可以使用 join
来执行此操作:
delete t
from table t join
(select assoc_case, participant, document, max(created) as maxc
from table
group by assoc_case, participant, document
) tt
on t.assoc_case = tt.assoc_case and t.participant = tt.participant and
t.document = tt.document
where t.created < tt.maxc;
关于mysql - 如何删除除最近行以外的所有其他列相同的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32000480/