MySQL - 使用相同的密钥更新兄弟姐妹
尚未找到解决方案...虽然这可能是一个新手问题,但我无法克服...希望有人可以伸出援手。
我有一个 MySQL 表,其中包含:
块引用
Col1 Col2
Row1 A null
Row2 A A1
Row3 A null
Row4 B null
Row5 B B1
etc
> Blockquote
如何构建 SQL 更新来更新 Col2,以便 Col2 上的值替换 null,即 C2R1 和 C2R3 获取 A1,C2R4 获取 B1 ?
Couldn't find a solution yet... although it is probably a newbie question, I haven't been able to overcome... hope someone can give a hand.
I have a MySQL table that has:
Blockquote
Col1 Col2
Row1 A null
Row2 A A1
Row3 A null
Row4 B null
Row5 B B1
etc
> Blockquote
How do I construct an SQL update to update Col2, so that the values on Col2 replace the null, ie, C2R1 and C2R3 gets A1, and C2R4 gets B1 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以按如下方式计算所需的值:
然后您可以删除/截断原始表并使用这些值重新创建它,或者如果您无法删除该表,则可以执行多表 更新。
You can calculate the required values as follows:
You can then either drop/truncate the original table and recreate it using these values, or if you can't drop the table you can instead perform a multi-table update.
尽管它可能不起作用(因为 MySQL 文档指出当前,您无法更新表并在子查询中从同一个表中进行选择。),但您应该尝试使用以下方法:
Although it might not work (because the MySQL documentation states that Currently, you cannot update a table and select from the same table in a subquery.), you should try with something like: