简体   繁体   English

在子查询中选择多个字段

[英]Selecting multiple fields in subquery

This ABAP code works:此 ABAP 代码有效:

  select *
   into table <sub_result>
  from ADRC
  WHERE ADDRNUMBER
  in ( select ADRNRA from AUFK where (cond_string) ).

But this does not:但这不会:

  select *
   into table <sub_result>
  from ADRC
  WHERE (ADDRNUMBER, MANDT)
  in ( select ADRNRA, MANDT from AUFK where (cond_string) ).

AFAIK the tuple syntax (ADDRNUMBER, MANDT) is valid for SQL. AFAIK元组语法(ADDRNUMBER, MANDT)对SQL有效。 Is this not valid in Open SQL of ABAP?这在 ABAP 的 Open SQL 中无效吗?

If the tuple syntax is not allowed, what could I do?如果不允许元组语法,我该怎么办?

PS In Open SQL checking for MANDT is not needed, so this is only sample query. PS在 Open SQL 中不需要检查 MANDT,所以这只是示例查询。

You can not use in for multiple columns.您不能将 in 用于多列。 Try like this:像这样尝试:

SELECT *
  INTO table <sub_result>
  FROM ADRC d
  WHERE exists ( select 1 from AUFK a where a~ADDRNUMBER = d~ADDRNUMBER and a~MANDT = d~MANDT)

To complete Pelin's answer, here are two possible syntaxes, depending on the ABAP version :要完成 Pelin 的回答,这里有两种可能的语法,具体取决于 ABAP 版本:

DATA sflights TYPE TABLE OF sflight.

" Strict mode of OpenSQL (>= 7.40 SP 5 ; more syntaxes than old OpenSQL syntax)

SELECT * FROM sflight AS f INTO TABLE @sflights  " <== @ activates the strict mode
  WHERE NOT EXISTS ( SELECT 1 FROM sbook AS b    " <== 1 is possible in strict mode
        WHERE b~carrid = f~carrid
          AND b~connid = f~connid
          AND b~fldate = f~fldate ).

" "Loose" mode of OpenSQL (strict mode not used)

SELECT * FROM sflight AS f INTO TABLE sflights " <== no @ i.e. strict mode deactivated
  WHERE NOT EXISTS ( SELECT * FROM sbook AS b  " <== 1 is not possible
        WHERE b~carrid = f~carrid
          AND b~connid = f~connid
          AND b~fldate = f~fldate ).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM