Access DB 查询 - 需要帮助更新某些记录

发布于 2024-07-13 11:47:46 字数 524 浏览 4 评论 0原文

我有一个访问数据库,我们用它来跟踪票证。 由于与该票证相关联的不同节目更改,每张票证可能会多次出现。 每条记录还有一个program_type字段,可以是SVR或VB。 示例:

123456 - SVR - SomeCode

123456 - VB - SomeVBCode

我在数据库中添加了一列名为 VB_Flag 的列,该列默认为 0,我想将每张包含 VB 代码的票证更改为数字 1。 因此,这里的结果将是:

123456 - SVR - SomeCode - 1

123456 - VB - SomeVBCode - 1

但是,我一生都无法弄清楚如何编写此更新查询。 起初我尝试过:

UPDATE table SET VB_Flag = 1 WHERE program_type = 'VB'

但这显然遗漏了所有与 VB 代码共享票号的 SVR 代码。

我不知所措。 帮助?

I have an access DB which we use to track tickets. Each ticket may have multiple occurrences because of different programming changes associated with that ticket. Each record also has a program_type field which is SVR or VB. Example:

123456 - SVR - SomeCode

123456 - VB - SomeVBCode

I've added a column to the database called VB_Flag, which defaults to 0, which I would like to change to the number 1 for every ticket containing VB code. So, the result here would be:

123456 - SVR - SomeCode - 1

123456 - VB - SomeVBCode - 1

But, I can't figure out for the life of me how to write this update query. At first I tried:

UPDATE table SET VB_Flag = 1 WHERE program_type = 'VB'

But that obviously left out all the SVR code that shared a ticket number with the VB code.

I'm at a loss. Help?

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

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

发布评论

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

评论(4

绝對不後悔。 2024-07-20 11:47:46

您可以执行以下操作:

UPDATE tickets SET VB_Flag = 1
WHERE ticket_id IN (SELECT ticket_id FROM tickets WHERE program_type = 'VB');

内部 SELECT 语句返回program_type 为“VB”的所有ticket_id 的列表。

然后,更新将具有这些 Ticket_id 之一的所有记录(包括那些program_type 为“SVR”的记录)的 VB_Flag 设置为 1。

You can do something like this:

UPDATE tickets SET VB_Flag = 1
WHERE ticket_id IN (SELECT ticket_id FROM tickets WHERE program_type = 'VB');

The inner SELECT statement returns a list of all ticket_ids that have a program_type of 'VB'.

The update then sets the VB_Flag to 1 for ALL records with one of those ticket_ids (that includes those with a program_type of 'SVR'.

剑心龙吟 2024-07-20 11:47:46

这应该有效:

UPDATE table SET VB_Flag = 1 
WHERE TicketNum IN (SELECT TicketNum FROM Table WHERE program_type = 'VB')

This should work:

UPDATE table SET VB_Flag = 1 
WHERE TicketNum IN (SELECT TicketNum FROM Table WHERE program_type = 'VB')
醉生梦死 2024-07-20 11:47:46

更新
桌子
内连接表 AS 表2
ON 表.TicketNumber = Table2.TicketNumber

表2.VB_Flag = 1
在哪里
(([表].[程序类型]="VB"))

UPDATE
Table
INNER JOIN Table AS Table2
ON Table.TicketNumber = Table2.TicketNumber
SET
Table2.VB_Flag = 1
WHERE
(([Table].[program_type]="VB"))

羁客 2024-07-20 11:47:46

一个简单的嵌套选择应该可以解决您的问题:

UPDATE myTable
SET VB_Flag = 1 
WHERE TicketID in (Select TicketID from myTable WHERE program_type = 'VB')

A simple nested select should take care of your problem:

UPDATE myTable
SET VB_Flag = 1 
WHERE TicketID in (Select TicketID from myTable WHERE program_type = 'VB')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文