gpt4 book ai didi

php - 将列更新为组中的最小值

转载 作者:行者123 更新时间:2023-11-29 14:34:51 25 4
gpt4 key购买 nike

我有这样的数据库

 uniqueid |     name    | newid | sirname
----------+-------------+-------+---------
A1 | Adam | NULL | Danny
A2 | Adam (Lee) | NULL | Danny
A5 | Adam (Koh) | NULL | Danny
B4 | Bruce | NULL | CK
B6 | Bruce (Lee)| NULL | CK

如何将newid更新为min(unique id)来自group by Sirname

我想要的结果:

 uniqueid |     name    | newid | sirname
----------+-------------+-------+---------
A1 | Adam | A1 | Danny
A2 | Adam (Lee) | A1 | Danny
A5 | Adam (Koh) | A1 | Danny
B4 | Bruce | B4 | CK
B6 | Bruce (Lee) | B4 | CK

最佳答案

试试这个:

UPDATE table a 
SET new_id = (SELECT MIN(unique_id)
FROM table b
WHERE b.sirname = a.sirname)

关于php - 将列更新为组中的最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9278947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com