我试过了,但无法返回所有行。它只返回左侧查询中的一些行。请找出错误。
SELECT c.star_ident, c.fix_ident
from corept.std_star_leg as c
INNER JOIN
(
SELECT star_ident,
transition_ident,
max(sequence_num) seq,
route_type
FROM corept.std_star_leg
WHERE data_supplier='J'
AND airport_ident='KOPF'
group by star_ident,transition_ident
) b
ON c.sequence_num=b.seq
and c.star_ident=b.star_ident
and c.transition_ident=b.transition_ident
LEFT OUTER JOIN
(
SELECT name,
trans
FROM skyplan_deploy.deploy_stars d
WHERE apt='KOPF'
AND name!=trans
) as x
on x.name=c.star_ident
and x.trans=c.transition_ident
where c.data_supplier='J'
and c.airport_ident='KOPF'
and x.name is null;
让corept.std_star_leg
表是这样的。
star_ident transition_ident sequence_num fix_ident airport
A XX 10 QWE KOPF
A XX 20 WER KOPF
A XX 30 HYU KOPF
A XX 40 GJI KOPF
B YY 10 SJI KOPF
B YY 20 DJI KOPF
B YY 30 FJI KOPF
B YY 40 GHI KOPF
B YY 50 KDI KOPF
执行内部连接后,将获得如下结果。
A XX 40 GJI
B YY 50 KDI
从而检索最大sequence_num
行数。之后,skyplan_deploy.deploy_stars
表格将如下所示。
apt name trans
KOPF A FJI
KOPF A DHI
KOPF B VNM
我需要输出
A GJI
B KDI