我有两个表用相同的键 . 我想在一个SELECT中, without subsequent manipulation of data in an internal table ,检索左侧表中右侧表中没有CORRESPONDING记录的所有记录(即右侧表中的列将为空) .
最合乎逻辑的做法是以下内容,但这不能编译,因为您可能不会在WHERE子句的外部联接中使用右侧的字段:
select e~equnr into lt_equnr
from equi as e
left outer join eqbs as b on e~equnr = b~equnr
where e~matnr = material
and b~b_werk = space.
看起来很有前途和编译的替代方法是这样,但它不起作用,因为它甚至会带回右边表中具有相应条目的那些:
select e~equnr into table lt_equnr
from equi as e
left outer join eqbs as b on e~equnr = b~equnr
and b~b_werk = space
where e~matnr = material.
此选项仅从右侧清空字段,但仍包含结果集中的所有内容 . 这可以通过从右侧选择字段来确认 .
另一个选项,也不起作用,是使用子选择:
select e~equnr into table lt_equnr
from equi as e
where e~matnr = material
and e~equnr not in ( select equnr from equi where equnr = e~equnr ).
2 回答
正如对该问题的评论中所指出的,我的代码中存在一个错误 . 在我的子选择中,我使用的是LHS表 . (我的子选择是引用EQUI而不是EQBS) .
通过修复我的子选择,它可以工作:
您可以使用子查询来尝试它: