Access DB 查询 - 需要帮助更新某些记录
我有一个访问数据库,我们用它来跟踪票证。 由于与该票证相关联的不同节目更改,每张票证可能会多次出现。 每条记录还有一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以执行以下操作:
内部 SELECT 语句返回program_type 为“VB”的所有ticket_id 的列表。
然后,更新将具有这些 Ticket_id 之一的所有记录(包括那些program_type 为“SVR”的记录)的 VB_Flag 设置为 1。
You can do something like this:
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'.
这应该有效:
This should work:
更新
桌子
内连接表 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"))
一个简单的嵌套选择应该可以解决您的问题:
A simple nested select should take care of your problem: