多条数据只更新最新的一条
例如table_a表数据如下
| rule_id | policy_number | status | create_time |
|---|---|---|---|
| 10001 | 00000102200553 | 1 | 2022-05-07 |
| 10002 | 00000102200553 | 1 | 2022-05-08 |
| ... |
update table_a
set rule_id =10003
where policy_number = '00000102200553'
and status = '1'
-- 根据时间倒序,然后只更新一条
order by create_time desc limit 1;
update后面如果跟limit 10则表示更新命中条件的其中10行数据。
更新后的数据
| rule_id | policy_number | status | create_time |
|---|---|---|---|
| 10001 | 00000102200553 | 1 | 2022-05-07 |
| 10003 | 00000102200553 | 1 | 2022-05-08 |
| ... |
