灵活的搜索查询 UNION
Flexible Search Query UNION
我想在这个查询中添加一个 UNION,我应该把 UNION 放在哪里(不关心 UNION 的代码,我只是想知道我可以把它放在哪里)在下面的灵活搜索中查询(我不熟悉语法)
SELECT DISTINCT {o:pk} FROM
(
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory AS h JOIN CronJobResult AS r ON {h.result} = {r.pk} }
WHERE {h.cronJobCode} = 'ordersCronJob' AND {r.code} = 'SUCCESS'
}}
) LAST,
(
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory as h}
WHERE {h.cronJobCode} = 'ordersCronJob'
}}
) CURRENT, {Order AS o
JOIN PaymentMode AS pm ON {pm.pk} = {o:paymentMode}
JOIN BaseStore AS b ON {o.store} = {b.PK}
JOIN OrderProcess AS op ON {o.pk} = {op.order}
}
WHERE (({pm:code} != 'asm' AND {op:creationtime} > LAST.startTime AND {op:creationtime} <= CURRENT.startTime)
OR ({pm:code} = 'asm' AND {o:asmActivationTime} > LAST.startTime AND {o:asmActivationTime} <= CURRENT.startTime) )
AND {o:originalVersion} IS NULL
AND 'rows-eu,rows-es' LIKE CONCAT( '%', CONCAT( {b.uid} , '%' ) )
AND {op.processDefinitionName} LIKE 'order-process%'
我试过将它放在最后一行,但它无法编译。
有什么提示吗?
对于 UNION 查询或 INNER 查询,您需要将相应的查询用双花括号括起来。
{{..query1..}} UNION {{..query2..}}
查看下面的示例以获取灵活的查询联合示例。
SELECT uniontable.PK, uniontable.CODE FROM
(
{{
SELECT {c:PK} as PK, {c:code} AS CODE FROM {Chapter AS c}
WHERE {c:PUBLICATION} LIKE ?pk
}}
UNION ALL
{{
SELECT {p:PK} as PK, {p:code} AS CODE FROM {Page AS p}
WHERE {p:PUBLICATION} LIKE ?pk
}}
) uniontable
您可以在以下位置找到 FlexibleSearch 提示和技巧
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8bc36ba986691014b48be171221d1f4f.html
希望对您有所帮助!
已修复您查询的前半部分...
SELECT tbl.startTime FROM
(
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory AS h JOIN CronJobResult AS r ON {h.result} = {r.pk} }
WHERE {h.cronJobCode} = 'ordersCronJob' AND {r.code} = 'SUCCESS'
}}
UNION
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory as h}
WHERE {h.cronJobCode} = 'ordersCronJob'
}}
) tbl
我想在这个查询中添加一个 UNION,我应该把 UNION 放在哪里(不关心 UNION 的代码,我只是想知道我可以把它放在哪里)在下面的灵活搜索中查询(我不熟悉语法)
SELECT DISTINCT {o:pk} FROM
(
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory AS h JOIN CronJobResult AS r ON {h.result} = {r.pk} }
WHERE {h.cronJobCode} = 'ordersCronJob' AND {r.code} = 'SUCCESS'
}}
) LAST,
(
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory as h}
WHERE {h.cronJobCode} = 'ordersCronJob'
}}
) CURRENT, {Order AS o
JOIN PaymentMode AS pm ON {pm.pk} = {o:paymentMode}
JOIN BaseStore AS b ON {o.store} = {b.PK}
JOIN OrderProcess AS op ON {o.pk} = {op.order}
}
WHERE (({pm:code} != 'asm' AND {op:creationtime} > LAST.startTime AND {op:creationtime} <= CURRENT.startTime)
OR ({pm:code} = 'asm' AND {o:asmActivationTime} > LAST.startTime AND {o:asmActivationTime} <= CURRENT.startTime) )
AND {o:originalVersion} IS NULL
AND 'rows-eu,rows-es' LIKE CONCAT( '%', CONCAT( {b.uid} , '%' ) )
AND {op.processDefinitionName} LIKE 'order-process%'
我试过将它放在最后一行,但它无法编译。
有什么提示吗?
对于 UNION 查询或 INNER 查询,您需要将相应的查询用双花括号括起来。
{{..query1..}} UNION {{..query2..}}
查看下面的示例以获取灵活的查询联合示例。
SELECT uniontable.PK, uniontable.CODE FROM
(
{{
SELECT {c:PK} as PK, {c:code} AS CODE FROM {Chapter AS c}
WHERE {c:PUBLICATION} LIKE ?pk
}}
UNION ALL
{{
SELECT {p:PK} as PK, {p:code} AS CODE FROM {Page AS p}
WHERE {p:PUBLICATION} LIKE ?pk
}}
) uniontable
您可以在以下位置找到 FlexibleSearch 提示和技巧 https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8bc36ba986691014b48be171221d1f4f.html
希望对您有所帮助!
已修复您查询的前半部分...
SELECT tbl.startTime FROM
(
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory AS h JOIN CronJobResult AS r ON {h.result} = {r.pk} }
WHERE {h.cronJobCode} = 'ordersCronJob' AND {r.code} = 'SUCCESS'
}}
UNION
{{
SELECT
MAX({h.startTime}) AS startTime
FROM {CronJobHistory as h}
WHERE {h.cronJobCode} = 'ordersCronJob'
}}
) tbl