SELECT *
FROM
(SELECT *
FROM RHSTRYWLN7.RESULT R
INNER JOIN RHSTRYWLN7.PRODUCT P ON P.PRODUCT_CODE=R.PRODUCT_CODE
WHERE SOURCE_GUID='i0ad0105800000151b126c1c49def32b4'
AND DELETED='F'
AND DATE_CREATED > systimestamp-90
AND DATE_CREATED < systimestamp) AS A
INNER JOIN
(SELECT S.result_guid,
count(document_guid) DocCount
FROM RHSTRYWLN7.RESULT S
INNER JOIN RHSTRYWLN7.document D ON D.result_guid=S.Result_guid
WHERE SOURCE_GUID='i0ad0105800000151b126c1c49def32b4'
AND DELETED='F'
AND DATE_CREATED > systimestamp-90
AND DATE_CREATED < systimestamp
GROUP BY S.result_guid) AS B ON A.Result_guid=B.Result_guid
Am trying to run the above query in sqldeveloper and getting error saying:
ORA-00933: SQL command not properly ended.
When I run the sub queries independently it runs fine. What could be the issue?
答案 0 :(得分:1)
You don't need the As when giving a name to a subquery. You can try the below
SELECT *
FROM
(SELECT *
FROM RHSTRYWLN7.RESULT R
INNER JOIN RHSTRYWLN7.PRODUCT P ON P.PRODUCT_CODE=R.PRODUCT_CODE
WHERE SOURCE_GUID='i0ad0105800000151b126c1c49def32b4'
AND DELETED='F'
AND DATE_CREATED > systimestamp-90
AND DATE_CREATED < systimestamp) A
INNER JOIN
(SELECT S.result_guid,
count(document_guid) DocCount
FROM RHSTRYWLN7.RESULT S
INNER JOIN RHSTRYWLN7.document D ON D.result_guid=S.Result_guid
WHERE SOURCE_GUID='i0ad0105800000151b126c1c49def32b4'
AND DELETED='F'
AND DATE_CREATED > systimestamp-90
AND DATE_CREATED < systimestamp
GROUP BY S.result_guid) B ON A.Result_guid=B.Result_guid
答案 1 :(得分:0)
对表别名使用AS
关键字不是 ANSI SQL 标准。并且 Oracle 不支持。
同样适用于 FROM 子句中使用的子查询,称为内联视图 。请勿使用AS
关键字。
答案 2 :(得分:0)
请尝试以下查询并检查
SELECT R.*,
count(document_guid) OVER (PARTITION BY result_guid) DocCount
FROM RHSTRYWLN7.RESULT R
INNER JOIN RHSTRYWLN7.PRODUCT P
ON P.PRODUCT_CODE=R.PRODUCT_CODE
INNER JOIN RHSTRYWLN7.document D
ON D.result_guid=R.Result_guid
WHERE SOURCE_GUID='i0ad0105800000151b126c1c49def32b4'
AND DELETED='F'
AND DATE_CREATED > systimestamp-90
AND DATE_CREATED < systimestamp