WITH
c1 AS
(SELECT x.asset_server_controller AS controller
,x.asset_environment AS env
,x.pager_creation_date || ' ' || x.pager_creation_time AS ts
,+1 AS TYPE
FROM hub_asr_report x
WHERE x.asset_environment IS NOT NULL
AND x.asset_server_controller IS NOT NULL
UNION ALL
SELECT x.asset_server_controller AS controller
,x.asset_environment AS env
,x.pager_modify_date || ' ' || x.pager_modify_time AS ts
,-1 AS TYPE
FROM hub_asr_report x
WHERE x.asset_environment IS NOT NULL
AND x.asset_server_controller IS NOT NULL
ORDER BY ts, controller
),
c2 AS
(SELECT controller
,ts AS starttime
,lead(ts) over(PARTITION BY controller ORDER BY ts) AS endtime
,SUM([ 1 ] - [ - 1 ]) over(PARTITION BY controller ORDER BY ts rows unbounded preceding) AS cnt
FROM c1
pivot(COUNT(TYPE) FOR TYPE IN([ 1 ], [ - 1 ])) AS p
ORDER BY controller,starttime
)
SELECT *
FROM c2
WHERE cnt > 0
ORDER BY app, st
基本上这个代码需要在同一个控制器中同时发生某些事情时进行计数,我遇到了SUM函数的问题,我无法计算第一个事件开始但没有结束的时间间隔。
我收到以下错误消息:
- 00000 - "缺少表达"
醇>
*原因:
*操作:
行错误:26列:8
这是以SUM
开头的行。
出于某种原因,我在该行中收到错误/错误。有什么问题以及如何解决?
nc01b.dc02 2015-08-26 09:30:47 1
nc01b.dc02 2015-08-26 09:32:47 -1
nc02a.dc03 2015-08-26 12:18:11 1
nc02a.dc03 2015-08-26 12:18:12 1
nc02a.dc03 2015-08-26 12:18:13 1
nc02a.dc03 2015-08-26 12:18:13 1
nc02a.dc03 2015-08-26 12:18:19 1
nc02a.dc03 2015-08-26 12:18:20 1
nc02a.dc03 2015-08-26 12:18:20 1
nc02a.dc03 2015-08-26 12:18:21 1
nc02a.dc03 2015-08-26 12:19:19 -1
nc02a.dc03 2015-08-26 12:19:19 -1
nc02a.dc03 2015-08-26 12:21:31 -1
nc02a.dc03 2015-08-26 12:21:31 -1
nc02a.dc03 2015-08-26 12:21:34 -1
nc02a.dc03 2015-08-26 12:21:34 -1
nc02a.dc03 2015-08-26 12:21:34 -1
nc02a.dc03 2015-08-26 12:21:35 -1
nc01a.dc05 2015-08-26 16:32:28 1
nc01a.dc05 2015-08-26 16:32:30 1
nc01a.dc05 2015-08-26 16:34:16 1
nc01a.dc05 2015-08-26 16:34:21 1
nc01a.dc05 2015-08-26 16:34:24 1
nc01a.dc05 2015-08-26 16:34:25 1
nc01a.dc05 2015-08-26 16:34:25 1
nc01a.dc05 2015-08-26 16:34:26 1
nc01a.dc05 2015-08-26 16:34:30 1
nc01a.dc05 2015-08-26 16:36:02 -1
nc01a.dc05 2015-08-26 16:36:06 -1
nc01a.dc05 2015-08-26 16:36:10 -1
nc01a.dc05 2015-08-26 16:36:10 -1
nc01a.dc05 2015-08-26 16:36:10 -1
nc01a.dc05 2015-08-26 16:36:11 -1
nc01a.dc05 2015-08-26 16:36:14 -1
nc01a.dc05 2015-08-26 16:36:22 -1
nc01a.dc05 2015-08-26 16:38:11 -1
nc01a.dc05 2015-08-26 17:00:36 1
nc01a.dc05 2015-08-26 17:02:14 -1
nc01a.dc05 2015-08-26 17:04:10 1
nc01a.dc05 2015-08-26 17:04:11 1
nc01a.dc05 2015-08-26 17:04:14 1
nc01a.dc05 2015-08-26 17:04:15 1
nc01a.dc05 2015-08-26 17:04:16 1
nc01a.dc05 2015-08-26 17:04:17 1
nc01a.dc05 2015-08-26 17:04:18 1
nc01a.dc05 2015-08-26 17:04:44 1
这是C1查询的输出,我遇到的问题是C2,当我试图计算在同一个控制器中同时发生的事件的数量时。我想知道在同一时间发生的事件的确切数量,以确定那里存在问题。 1表示事件开始,-1表示事件已完成。
答案 0 :(得分:1)
SUM([1] - [ - 1])OVER
语法不正确。
如果要使用 WITH 子句中使用的列值,即+1和-1作为“type”,请在分析函数中提及别名“type”< strong> SUM()OVER()。
此外,在选择+
时无需放置1
,只需使用1
。我希望您理解,对于所有行,您的列值始终为1
。
我想你想要这样的东西:
SUM(type) OVER(...
FOR IN IN([1],[ - 1]))
这里也有类似的问题。您需要删除[
和]
这是一个无效的标识符。
我更喜欢 SQL * Plus ,您可以轻松地知道错误的来源。