使用具有多行和多列的条件更新表
问题描述:
您将如何更新 send = 1 仅在 video_id 中 'host' 等于 'cnn' 的位置
How would you do to update send = 1 only where in the video_id where 'host' is equal to 'cnn'
+----------+---------+------------+--------------+
| video_id | meta_id | upload_key | upload_value |
+----------+---------+------------+--------------+
| 1 | 6 | host | cnn |
| 1 | 7 | send | 0 |
+----------+---------+------------+--------------+
答
您可以使用 join
:
update t join
t tc
on t.video_id = tc.video_id and
tc.upload_key = 'host' and
tc.upload_value = 'cnn'
set t.upload_value = '1'
where t.upload_key = 'send' and t.upload_value <> '1';