gpt4 book ai didi

mysql - 连接列并返回空值 - MS access

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

我有两个表:

table 车:

RegNr      Sold
------- ------
ABC123 2015-12-27
ABC222
ABC333
ABC444

表格单位:

VIN       BuyerPayed
------ ----------
ABC123 2015-12-18
ABC222 2015-12-18
ABC333 NULL
ABC444 2015-12-19

我看到 ABC222 和 ABC444 已收到买方的付款,因此我想要一个查找 ABC222 ABC444 的 SELECT 语句。

我已经尝试过

Select cars.regnr, cars.sold, Unit.BuyerPayedDate from Unit Inner Join cars on cars.regnr= unit.vin where cars.sold is Null and Unit.BuyerPayed is Not Null;

但我得到了一些尴尬的结果。

请帮忙。

最佳答案

您可以使用带有联接的 UPDATE 查询:

update
cars inner join unit on cars.RegNr = unit.VIN
set
cars.Sold = unit.BuyerPayed

并且(取决于您想要实现的逻辑)您可能需要添加此条件:

where
cars.Sold IS NULL

这将更新汽车 ABC222ABC444,但不会更新 ABC123,因为它已经有售出日期。

如果您不想更新表,而只想选择需要更新的行,则可以使用此查询:

select cars.RegNr
from
cars inner join unit on cars.RegNr = unit.VIN
where
cars.Sold IS NULL
and unit.BuyerPayed IS NOT NULL

关于mysql - 连接列并返回空值 - MS access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34787902/

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