根据另一列中的相等值更新列值
正在
起点
Parcelid | 地址 |
---|---|
44 | Street |
32 | Yyyy |
44 | 空 |
44 | 空 |
44 | 12 |
12 | 街 |
| |
---|---|
| XXXX |
Street | |
: | 空 |
: | 使用 |
Workbench | 号 |
我 | MySQL Zzzz |
基本上,如果它们具有相同的包裹,我想填充同一表的同一列。我通过自我加入来读到这一点,我可以解决这个问题,到目前为止,我已经写了这篇文章:有帮助吗?
UPDATE table t1
INNER JOIN table t2 ON t1.ParcelID = t2.ParcelID
SET t1.Address = IF(t2.Address = '' OR NULL, t2.Address, t1.Address)
WHERE t1.ParcelID = t2.ParcelID;
有什么建议吗?写在其中的条款冗余吗?
预先感谢^^
I'm using MySQL Workbench:
Starting point:
ParcelID | Address |
---|---|
44 | street xxxx |
32 | street yyyy |
44 | empty |
44 | null |
12 | empty |
12 | street zzzz |
What should be:
ParcelID | Address |
---|---|
44 | street xxxx |
32 | street yyyy |
44 | street xxxx |
44 | street xxxx |
12 | street zzzz |
12 | street zzzz |
Basically, I want to populate that same column of the same table if they have the same ParcelID. I read around that with a self join I could solve the problem, so far I've written this: any help?
UPDATE table t1
INNER JOIN table t2 ON t1.ParcelID = t2.ParcelID
SET t1.Address = IF(t2.Address = '' OR NULL, t2.Address, t1.Address)
WHERE t1.ParcelID = t2.ParcelID;
any suggestions? Is writing the WHERE clause redundant?
Thanks in advance ^^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个选项可以是将条件移动在JOIN和SET ADDEM2内部,如跟随:
Demo 在这里。
One option could be moving the condition inside the join and set address2 to address1 directly, as done followingly:
Demo here.