访问更新查询最小值

时间:2017-05-04 22:54:50

标签: sql ms-access

我正在尝试对“排名”字段的最低值运行更新查询。当我向查询添加其他条件时,查询会更新0条记录。这是查询:

UPDATE Table_Address SET Table_Address.Priority = True
WHERE (
((Table_Address.Priority)=False) AND 
((Table_Address.Order)=(SELECT MIN(Order) FROM Table_Address)) AND 
((Table_Address.ID)=[Forms]![Form_UpdateAddressInfo]![ID]) AND 
((Table_Address.Status)="Good" Or (Table_Address.Status)="Unknown"));

当我在没有以下条件的情况下运行查询时:Table_Address.Priority = False和(Table_Address.Status)=“Good”或(Table_Address.Status)=“Unknown”),查询将更新最低的“订单”地址。在我包含其他标准的那一刻(即:我想要最低有序地址,地址状态=好或未知,以及具有'假'优先级的地址状态)它会更新0条记录。我不太确定我在哪里出错了。谢谢。

1 个答案:

答案 0 :(得分:0)

如果我之前评论中的猜测是正确的,那么这可能就是您所需要的:

UPDATE Table_Address
SET Table_Address.Priority = True
WHERE
    Table_Address.ID=[Forms]![Form_UpdateAddressInfo]![ID]
    AND Table_Address.Order=(
    SELECT MIN(Order) FROM Table_Address
    WHERE
        Table_Address.Priority)=False
        AND Table_Address.ID=[Forms]![Form_UpdateAddressInfo]![ID]
        AND (Table_Address.Status="Good"
            Or Table_Address.Status="Unknown")
);