更新之前(原始示例表):
| document_id | meta_key | meta_value |
|---|---|---|
| 1 | iban | IBAN123456 |
| 1 | bankaccount | ACCT987654 |
| 2 | iban | IBAN555555 |
| 2 | bankaccount | ACCT444444 |
| 3 | iban | IBAN888888 |
| 3 | bankaccount | ACCT333333 |
运行SQL更新查询后:
| document_id | meta_key | meta_value |
|---|---|---|
| 1 | iban | IBAN123456 |
| 1 | bankaccount | IBAN123456 |
| 2 | iban | IBAN555555 |
| 2 | bankaccount | IBAN555555 |
| 3 | iban | IBAN888888 |
| 3 | bankaccount | IBAN888888 |
我需要一个查询来实现上述表格的结果吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
document_id,meta_key, andmeta_value. 您想要更新meta_key为bankaccount的行的meta_value,将其更新为meta_key为iban的行中相应的meta_value。以下是一个实现这个目标的SQL查询:
UPDATE example_table AS p1 INNER JOIN ( SELECT document_id, meta_value AS iban FROM example_table WHERE meta_key = 'iban' ) AS p2 ON p1.document_id = p2.document_id SET p1.meta_value = p2.iban WHERE p1.meta_key = 'bankaccount';在运行任何更新查询之前,请记得备份您的数据库,并在安全环境中进行测试!