更新表中的最小值

发布于 2024-09-16 04:08:58 字数 346 浏览 2 评论 0原文

我想根据同一个表的另一列的最小值更新表中的列。

例如。

JobPositonId | JobPositonName | JobDescriptionId | ContactId
1            | 1              | 1                | 1
2            | 1              | 1                | 0
3            | 1              | 1                | 0

我想将 ContactId 更新为 1,如果它是 0 并且其中 JobPositionId 最低。

I want to update a Column in a Table, based on the minimum of another column of the same table.

eg.

JobPositonId | JobPositonName | JobDescriptionId | ContactId
1            | 1              | 1                | 1
2            | 1              | 1                | 0
3            | 1              | 1                | 0

I want to update ContactId to be 1, if it is 0 and where JobPositionId is the lowest.

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

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

发布评论

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

评论(1

鹤舞 2024-09-23 04:08:58

我认为这应该有效:

update jobTable
   set contactid = 1
 where jobPostitionId in (select pos from (select min(jobPositionId) as pos from jobTable where contactId = 0) as subtable);

这是一种类似于此处描述的黑客(http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in- mysql/)。

I think this should work:

update jobTable
   set contactid = 1
 where jobPostitionId in (select pos from (select min(jobPositionId) as pos from jobTable where contactId = 0) as subtable);

It's kind of a hack similar to what's described here (http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文