Hybris灵活的搜索并集查询以获取产品

时间:2018-12-13 05:02:01

标签: sql hybris flexible-search

   code    Attribute1(String)

    A         C
    B         D
    C         Empty
    D         Empty 

如何获取所有A,B,C,D的pk

注意:使用字符串值C,D,我想使用灵活搜索查询来获取产品C,D的pk以及A,B

详细信息:

我有产品的清单。

这些产品中的每一个内部都有一个名为“ X”的属性,其中包含字符串类型的产品ID代码。

注意:“产品ID码”是指产品列表中另一个产品的“产品ID”。

现在我想根据产品ID代码获取产品的pk吗?

1 个答案:

答案 0 :(得分:0)

我不太了解,但是您可以尝试这样

select {p1.pk},{p2.pk} from {product as p1},{product as p2} WHERE {p1.Attribute1} = {p2.code}

您可以为其添加过滤器

 AND {p1.Attribute1} in ('C','D')

使用UNION

SELECT uniontable.PK FROM
(
   {{
      SELECT {p1:PK} AS PK FROM {Product AS p1},{Product AS p2} 
      WHERE {p1.code} = {p2.Attribute1}
   }}
   UNION ALL
   {{
      SELECT {p:PK} AS PK FROM {Product AS p}
      WHERE {p1.Attribute1} is not empty
   }}
) uniontable

带过滤器

SELECT uniontable.PK FROM
(
   {{
      SELECT {p1:PK} AS PK FROM {Product AS p1},{Product AS p2} 
      WHERE {p1.code} = {p2.Attribute1} AND {p2.Attribute1} in ('C','D')
   }}
   UNION ALL
   {{
      SELECT {p:PK} AS PK FROM {Product AS p}
      WHERE {p.Attribute1} in ('C','D')
   }}
) uniontable