【发布时间】:2021-02-24 10:53:23
【问题描述】:
大家好,我是这个版块的新手,以前我总是匿名查看,但现在我有一个特定的问题,我找不到答案。
我有两个语句分别做得很好
声明 1:选择问题最多的网站
WITH ordered_query AS
(SELECT debitorid, objectid, count(incident) as CTINCI
FROM ssrs_tblx_sla STSLA
WHERE Debitorid = :Debitor
group by debitorid, objectid
ORDER BY count(Incident) DESC, debitorid)
SELECT debitorid, objectid, CTINCI
FROM ordered_query
WHERE rownum <= 5
声明 2:网站的大多数错误代码
WITH ordered_query AS
(SELECT debitorid, objectid, errorcode, count(incident) as CTINCI
FROM ssrs_tblx_sla STSLA
WHERE Debitorid = :Debitor
and objectid = :Objectid
group by debitorid, objectid, errorcode
ORDER BY count(Incident) DESC, debitorid)
SELECT debitorid, objectid, errorcode, CTINCI
FROM ordered_query
WHERE rownum <= 5
在这两个语句中,我在 where 语句中使用 oracle 参数。
现在我想将它们组合起来并通过 LEFT JOIN 语句进行尝试,但似乎我不能在语句 2 的 where 子句中使用语句 1 的值。
目标:我想获得事件数量最多的前 5 个站点,并且每个站点的每个错误代码中事件数量最多的前 5 个站点
有人知道我做错了什么吗?我有点迷茫
select T5S.Debitorid
, T5S.Objectid
, T5S.CTINCI as SiteTotal
, T5P.ERRORCODE
, T5P.CTINI as ERCTotal
FROM
(WITH ordered_query AS
(SELECT debitorid, objectid, count(incident) as CTINCI
FROM ssrs_tblx_sla STSLA
WHERE Debitorid = :Debitor
group by debitorid, objectid
ORDER BY count(Incident) DESC, debitorid)
SELECT debitorid, objectid, CTINCI
FROM ordered_query
WHERE rownum <= 5
) T5S
LEFT JOIN
(WITH ordered_query AS
(SELECT debitorid, objectid, errorcode, count(incident) as CTINCI
FROM ssrs_tblx_sla STSLA
WHERE Debitorid = T5S.Debitorid
and objectid = T5S.Objectid
group by debitorid, objectid, errorcode
ORDER BY count(Incident) DESC, debitorid)
SELECT debitorid, objectid, errorcode, CTINCI
FROM ordered_query
WHERE rownum <= 5
) T5P
ON T5S.Debitorid = T5P.DebitorId and T5S.objectid=T5P.objectid
oracle给我的错误码是:
ORA-00904:“T5S”。“OBJECTID”:标识符无效
00904. 00000 - “%s:无效标识符”
*原因:
*行动:
Zeile 的 Fehler:20 斯帕尔特:56
【问题讨论】:
标签: oracle join parameters row-number with-statement