执行以下查询后,我从两个目录"目录A"和"目录B"中获取所有产品的UNION"查询:
SELECT uniontable.PK, uniontable.creationtime AS TIMECREATED FROM
(
{{
SELECT {p:mode},{p:brandno},{creationtime} AS creationtime FROM {Product AS p JOIN catalogversion AS cv ON
{p:catalogversion}={cv:pk} JOIN catalog AS cat ON {p:catalog}={cat:pk}}
WHERE {p.code} = '145' AND {cv:version}='Staged' AND {cat:id}='catalogA'
}}
UNION ALL
{{
SELECT {p:mode},{p:brandno},{creationtime} AS creationtime FROM {Product AS p JOIN catalogversion AS cv ON
{p:catalogversion}={cv:pk} JOIN catalog AS cat ON {p:catalog}={cat:pk}}
WHERE {p.code} = '123' AND {cv:version}='Staged' AND {cat:id}='catalogB'
}}
) uniontable ORDERR BY TIMECREATED
我只需要来自 UNION 查询的 CatalogA 的产品,所以我做了一个子查询,如下所示,但它抛出错误。任何帮助将不胜感激?
查询 2 :
SELECT uniontable.PK, uniontable.creationtime AS TIMECREATED FROM {Product AS p JOIN catalogversion AS cv ON
{p:catalogversion}={cv:pk} JOIN catalog AS cat ON {p:catalog}={cat:pk}}
WHERE {cv:version}='Staged' AND {cat:id}='catalogA' IN
(
{{
SELECT {p:mode},{p:brandno},{creationtime} AS creationtime FROM {Product AS p JOIN catalogversion AS cv ON
{p:catalogversion}={cv:pk} JOIN catalog AS cat ON {p:catalog}={cat:pk}}
WHERE {p.code} = '145' AND {cv:version}='Staged' AND {cat:id}='catalogA'
}}
UNION ALL
{{
SELECT {p:mode},{p:brandno},{creationtime} AS creationtime FROM {Product AS p JOIN catalogversion AS cv ON
{p:catalogversion}={cv:pk} JOIN catalog AS cat ON {p:catalog}={cat:pk}}
WHERE {p.code} = '123' AND {cv:version}='Staged' AND {cat:id}='catalogB'
}}
) uniontable ORDERR BY TIMECREATED
你只需要用WHERE uniontable.catalog = 'catalogA'
过滤临时表
喜欢
SELECT * FROM
(
{{
SELECT {p:pk},{p:mode},{p:brandno},{creationtime} AS creationtime, {cat:id} AS catalog
FROM { Product AS p
JOIN catalogversion AS cv ON {p:catalogversion}={cv:pk}
JOIN catalog AS cat ON {p:catalog}={cat:pk}
}
WHERE {p.code} = '145' AND {cv:version}='Staged' AND {cat:id}='catalogA'
}}
UNION ALL
{{
SELECT {p:pk},{p:mode},{p:brandno},{creationtime} AS creationtime, {cat:id} AS catalog
FROM { Product AS p
JOIN catalogversion AS cv ON {p:catalogversion}={cv:pk}
JOIN catalog AS cat ON {p:catalog}={cat:pk}
}
WHERE {p.code} = '123' AND {cv:version}='Staged' AND {cat:id}='catalogB'
}}
) as uniontable WHERE uniontable.catalog = 'catalogA' ORDERR BY uniontable.creationtime