2

现在收到以下错误:

ORA-30484: missing window specification for this function
30484. 00000 -  "missing window specification for this function"
*Cause:    All window functions should be followed by window specification,
           like <function>(<argument list>) OVER (<window specification>)
*Action:
Error at Line: 17 Column: 72

更新代码(根据 Aaron Hall 的建议)

select meter_id,
to_char(interval_time_local,'dd-mon-yyyy hh24:mi') as gap_start,
to_char(next_interval_time_local,'dd-mon-yyyy hh24:mi') as gap_finish
from (
                select i1.device_id as meter_id
                          ,interval_time_local
                          ,SUM(CASE i1.chan_num WHEN 0 THEN i1.chan_value * 2 ELSE 0 END) as chan0
                          ,SUM(CASE i1.chan_num WHEN 2 THEN i1.chan_value * 2 ELSE 0 END) as chan1
                          ,SUM(CASE i1.chan_num WHEN 1 THEN i1.chan_value * 2 ELSE 0 END) as chan2
                          ,SUM(CASE i1.chan_num WHEN 3 THEN i1.chan_value * 2 ELSE 0 END) as chan3
                          ,lead(interval_time_local,1) over (order by device_id, interval_time_local) as next_interval_time_local
                from gn_owner_demo.ami_read_interval i1
                where created_utc = ( select max(created_utc)
                                                                from gn_owner_demo.ami_read_interval i2
                                                                where i2.device_id = i1.device_id
                                                                and i2.interval_time_local = i1.interval_time_local)
                group by device_id, interval_time_local, i1.device_id, lead(interval_time_local,1)
                order by device_id, interval_time_local
                )
where interval_time_local <> next_interval_time_local - 30/1440;

我继承了一些提取数据间隙的代码。我从未使用过 OVER 子句,因此不确定它是否正确使用。错误信息是:

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"
*Cause:    
*Action:
Error at Line: 11 Column: 134

这是查询 - 我在 SQL 开发人员中运行:

select meter_id
,to_char(gn_owner_demo.interval_time_local,'dd-mon-yyyy hh24:mi') as gap_start
,to_char(gn_owner_demo.next_interval_time_local,'dd-mon-yyyy hh24:mi') as gap_finish
from (
select i1.device_id as meter_id
    ,interval_time_local
    ,SUM(CASE i1.chan_num WHEN 0 THEN i1.chan_value * 2 ELSE 0 END) as chan0
    ,SUM(CASE i1.chan_num WHEN 2 THEN i1.chan_value * 2 ELSE 0 END) as chan1
    ,SUM(CASE i1.chan_num WHEN 1 THEN i1.chan_value * 2 ELSE 0 END) as chan2
    ,SUM(CASE i1.chan_num WHEN 3 THEN i1.chan_value * 2 ELSE 0 END) as chan3
    ,lead(gn_owner_demo.interval_time_local,1) over (order by gn_owner_demo.device_id, gn_owner_demo.interval_time_local) gn_owner_demo.next_interval_time_local
from gn_owner_demo.ami_read_interval i1
where gn_owner_demo.created_utc = ( select max(gn_owner_demo.created_utc)
            from gn_owner_demo.ami_read_interval i2
            where i2.device_id = i1.device_id
            and i2.interval_time_local = i1.interval_time_local)
group by gn_owner_demo.device_id, gn_owner_demo.interval_time_local
order by gn_owner_demo.device_id, gn_owner_demo.interval_time_local
)
where gn_owner_demo.interval_time_local <> gn_owner_demo.next_interval_time_local - 30/1440;
4

1 回答 1

2

是什么gn_owner_demo.interval_time_local

您的from子句引用了,gn_owner_demo.ami_read_interval所以我假设它gn_owner_demo是模式名称并且ami_read_interval是表的名称。但是,如果这是正确的,则意味着它gn_owner_demo.interval_time_local指的是一个单独的表,该表interval_time_local也归gn_owner_demo. 如果那实际上是一个单独的表,则您需要加入该表。不过,我的猜测是,您确实想引用表interval_time_local中的列,gn_owner_demo.interval_time_local并且这适用于您以这种方式引用的其他列,在这种情况下,您将使用il别名,即

lead( il.interval_time_local, 1 )
   over( order by il.device_id,
                  il.interval_time_local) as next_interval_time_local

现在,我怀疑您真的想要partition byil.device_id不是将其包含在其中,order by但是由于您没有告诉我们您的数据是什么样的或您想要的结果是什么,这只是我的猜测。

如果我的猜测是正确的,您还需要以类似的方式更改WHEREGROUP BYORDER BY子句,以便您从正在查询的表中引用列名,而不是表别名。

于 2014-06-02T01:09:03.763 回答