更新带有同一ID -MySQL的最后记录字段的NULL字段

发布于 2025-01-25 16:48:56 字数 1525 浏览 3 评论 0原文

我需要使用先前记录的卖方更新Colucm“ seller_name”下的空字段 具有相同“ product_id”字段的名称。例如,下表:

product_idiyro
IGmpiysusu
2152514625iyro
ig2185564723
OTI1178042531
</2152514625
强>2185564723
strongseller_name
1330811490
iokunull
TSUG595898812
TSUG595898812
null

Product_id

iyroIG
21855647232152514625
2152514625
最终
输出1178042531
mpiysusuSeller_name
mpiysusuyi
2152514625
mpiysusuyi2152514625
ioku1330811490
tsug595898812
tsug595898812
oti oti oti1178042531

我是新的解释。

I need to UPDATE null fields under the colucm "seller_name" with previously recorded seller
names that have the same "Product_ID" field. For example given the following table:

seller_nameProduct_ID
iYRO ig2185564723
Mpiysusu2152514625
iYRO ig2185564723
oti1178042531
NULL2152514625
NULL2152514625
Mpiysusuyi2152514625
NULL2152514625
ioKU1330811490
Tsug595898812
Tsug595898812
NULL1178042531

The final output should be:

seller_nameProduct_ID
iYRO ig2185564723
Mpiysusu2152514625
iYRO ig2185564723
oti1178042531
Mpiysusu2152514625
Mpiysusu2152514625
Mpiysusuyi2152514625
Mpiysusuyi2152514625
ioKU1330811490
Tsug595898812
Tsug595898812
oti1178042531

I'm new into SQL so any explanation would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2025-02-01 16:48:56

我不知道其他值来自何处,但是如果您只想使用零值更新列,则可以尝试执行此操作。

Update mytable m Join (select seller_name, Product_ID from mytable 
group by Product_ID) k
on k.Product_ID = m.Product_ID
set m.seller_name = k.seller_name
where m.seller_name is null

I don't know where the other values came from but if you just want to update the column with the null values you can try to do this.

Update mytable m Join (select seller_name, Product_ID from mytable 
group by Product_ID) k
on k.Product_ID = m.Product_ID
set m.seller_name = k.seller_name
where m.seller_name is null
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文