gpt4 book ai didi

mysql - 在同一查询中使用查询结果

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

我正在 MS Access 2010 中使用一个相当大的 SQL 语句。如下:

SELECT 
W.ID AS wid,
W.wpt_ty AS ty,
W.wpt_num AS num,
W.wpt_nxt AS nxt,
W.latdeg AS lat,
W.londeg AS lon,
W.alt AS alt,
W.mission_id AS mid,
W.ctg1 AS ctg1,
W.ctg2 AS ctg2,
W.ctg3 AS ctg3,
W.ctg4 AS ctg4,
W.wpt_index AS indx,
W.vel AS vel,
W.tu AS tu,
R.route_num AS rnum,
R.AC_num AS ac,
R.route_type AS rtype,
R.LastUpdatedOn AS d8,
R.LastUpdatedBy AS auth,
R.flight_wpt_count AS wfcount,
M.mission_name AS msnName,
V.Description AS vstatus,
R.disallowed_reason_id AS did,
CW.wpt_num AS c1num,
CR.matching_route_id AS c1mrid,
CW.wpt_index AS c1indx,
CRU.runway_name AS c1rnwy,
CR.route_num AS c1rnum
FROM Validation AS V
(RIGHT JOIN Runways AS CRU
INNER JOIN (Routes CR
INNER JOIN Waypoints CW ON CR.ID = CW.route_id)
ON Runways.ID = Routes.runway_id
INNER JOIN ((Missions as M
INNER JOIN Routes AS R ON M.ID = R.mission_id)
INNER JOIN Waypoints AS W ON (R.ID = W.route_id)
AND (M.ID = W.mission_id)) ON
V.ID = R.validated
WHERE (((R.matching_route_id)=307543) AND ((R.validated) <> 0 ))
AND (((CW.mission_id)=mid) AND ((CW.wpt_num) = (ctg1))))

如果您查看底部,您可以看到我在右连接上引用值 ctg1mid,而内连接引用其他文字值。最终我想对 ctg2、ctg3 和 ctg4 执行相同的操作

现在我将它们作为两个单独的查询运行,但发现它太慢了。如果我可以加入组合查询(有点像我在这里展示的那样),它可以大大加快速度。但我不知道如何:

  • 在所述查询中之前从内/左连接中使用选择值,并将它们推送到右连接所需的值中。
  • 我可能错误地使用了联接,但我认为它们与组合来自可能相同表的数据有关,只是在不同的枢轴点上。
  • 如何使用 MS Access GUI 帮助编写这样的查询。
  • 我知道这是针对 MS Access 的,但我标记的是 MySQL,以防万一有类似的查询可以移植到 MS Access?

最佳答案

您是否尝试过使用 UNION 来实现此目的?

它将允许您执行此查询(作为两个查询,您提到了可能性),并将结果连接到输出。

请注意,它会吃掉(仅显示其中一个)结果集中的重复项。

为了您自己的利益,我还建议阅读以下答案中的不同类型的联接:

MYSQL Joins

关于mysql - 在同一查询中使用查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29379760/

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