gpt4 book ai didi

mysql - mySQL 上的 SQL 连接查询帮助

转载 作者:行者123 更新时间:2023-11-29 04:07:17 24 4
gpt4 key购买 nike

这是我的基本查询

 SELECT * from ACTIONS where STARTDATE < '2015-05-01'   and EXPORTDATE is null

我需要将其与表 Contracts 连接起来,并进一步仅包含两个表中 SERIAL 相同的记录和 ENDDATE(在 Contracts 中)< '2015-03-01'

查看数据后,我需要对 ACTIONS 进行更新查询,将相同记录的 STARTDATE 设置为新日期。

最佳答案

选择语句的连接:

SELECT * from ACTIONS 
JOIN Contracts ON Actions.Serial = Contracts.Serial
WHERE Actions.STARTDATE < '2015-05-01'
AND Actions.EXPORTDATE is null
AND Contracts.EndDate < '2015-03-01'

更新(使用带有连接语法的 MySQL 更新):

UPDATE Actions
JOIN Contracts ON Actions.Serial = Contracts.Serial
SET Actions.StartDate = 'NewDate'
WHERE Actions.STARTDATE < '2015-05-01'
AND Actions.EXPORTDATE is null
AND Contracts.EndDate < '2015-03-01'

如果您想缩短查询,您可以为表使用别名,例如 Contracts AS C然后使用这样的别名引用表:C.EndDate < '2015-03-01' .

关于mysql - mySQL 上的 SQL 连接查询帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28544918/

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