灵活的IN运算符搜索IN运算符?

2020-09-05 01:23发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


专家们,

执行下面的查询后,我从" catalogA"和" catalogB"两个目录中获得所有产品的UNION

  SELECT uniontable.PK,uniontable.creationtime按时间从
     (
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='145'并且{cv:version} ='Staging'和{cat:id} ='catalogA'
        }}
        全联盟
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='123'并且{cv:version} ='Staged'并且{cat:id} ='catalogB'
        }}
     )uniontable ORDERR BY TIMECREATED

  
  

我只需要UNION查询的CatalogA中的产品,所以我做了如下的子查询,但是它抛出错误。 任何帮助将不胜感激?

  SELECT uniontable.PK,uniontable.creationtime按{产品AS p JOIN catalogversion AS cv ON的时间递增
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {cv:version} ='Staging'和{cat:id} ='catalogA'IN
     (
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='145'并且{cv:version} ='Staging'和{cat:id} ='catalogA'
        }}
        全联盟
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='123'并且{cv:version} ='Staged'并且{cat:id} ='catalogB'
        }}
     )uniontable ORDERR BY TIMECREATED

   
   
   
   

  

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


专家们,

执行下面的查询后,我从" catalogA"和" catalogB"两个目录中获得所有产品的UNION

  SELECT uniontable.PK,uniontable.creationtime按时间从
     (
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='145'并且{cv:version} ='Staging'和{cat:id} ='catalogA'
        }}
        全联盟
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='123'并且{cv:version} ='Staged'并且{cat:id} ='catalogB'
        }}
     )uniontable ORDERR BY TIMECREATED

  
  

我只需要UNION查询的CatalogA中的产品,所以我做了如下的子查询,但是它抛出错误。 任何帮助将不胜感激?

  SELECT uniontable.PK,uniontable.creationtime按{产品AS p JOIN catalogversion AS cv ON的时间递增
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {cv:version} ='Staging'和{cat:id} ='catalogA'IN
     (
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='145'并且{cv:version} ='Staging'和{cat:id} ='catalogA'
        }}
        全联盟
        {{
           选择{p:mode},{p:brandno},{creationtime} AS创建时间,来自{Product AS p JOIN catalogversion AS AS cv ON
  {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
           {p.code} ='123'并且{cv:version} ='Staged'并且{cat:id} ='catalogB'
        }}
     )uniontable ORDERR BY TIMECREATED

   
   
   
   

  
付费偷看设置
发送
1条回答
Haoba3210
1楼-- · 2020-09-05 02:16

您可以这样做:

 从{Product AS p},{CatalogVersion AS cv},{Catalog AS cat}中选择{p:pk},{p:code},在{p:catalogversion} = {cv:pk}和{  p:catalog} = {cat:pk}和{cv:version} ='Staged'AND {cat:id} ='catalogA'和{p:pk} IN(
      选择uniontable.PK FROM
      (
         {{
                从{产品AS p加入目录版本AS cv ON中选择{p:pk} AS PK
       {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
                {p.code} ='145'并且{cv:version} ='Staging'和{cat:id} ='catalogA'
             }}
             全联盟
             {{
                从{产品AS p加入目录版本AS cv ON中选择{p:pk} AS PK
       {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
                {p.code} ='123'并且{cv:version} ='Staged'并且{cat:id} ='catalogB'
             }}
      )uniontable
  )订购{p:creationtime}
  

如果要使用 JOIN ,则可以使用以下查询,与上面给出的查询等效:

 从{Product AS p JOIN CatalogVersion AS cv ON中选择{p:pk},{p:code}
      {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
          {cv:version} ='Staged'AND {cat:id} ='catalogA'AND {p:pk} IN(
              选择uniontable.PK FROM
              (
                 {{
                        从{产品AS p加入目录版本AS cv ON中选择{p:pk} AS PK
               {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
                        {p.code} ='145'并且{cv:version} ='Staging'和{cat:id} ='catalogA'
                     }}
                     全联盟
                     {{
                        从{产品AS p加入目录版本AS cv ON中选择{p:pk} AS PK
               {p:catalogversion} = {cv:pk}加入目录as cat on {p:catalog} = {cat:pk}}
                        {p.code} ='123'并且{cv:version} ='Staged'并且{cat:id} ='catalogB'
                     }}
              )uniontable
  )订购{p:creationtime}
  

一周热门 更多>