簡體   English   中英

使用具有多行和多列的條件更新表

[英]Update table using condition with multiple rows and columns

僅在video_id中“主機”等於“ cnn”的情況下,如何更新send = 1

+----------+---------+------------+--------------+
| 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';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM