可以使用以下的 SQL 查询来实现该功能:

UPDATE your_table t1
JOIN (
    SELECT contract_number, MAX(year_month) AS max_year_month
    FROM your_table
    GROUP BY contract_number
) t2 ON t1.contract_number = t2.contract_number
SET t1.column1 = t2.column1,
    t1.column2 = t2.column2,
    ...
WHERE t1.year_month <> t2.max_year_month;

请将上述代码中的 'your_table' 替换为实际的表名,'column1', 'column2', ... 替换为实际的列名。这个查询将会根据合同号相同且年月不是最大年月的条件,更新同一合同其他年月的部分字段数据为最大年月的对应字段数据。


原文地址: https://www.cveoy.top/t/topic/pEPl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录