【问题标题】:ORA-06553: PLS-306 Max Count Across Multiple DaysORA-06553: PLS-306 多天的最大计数
【发布时间】:2017-08-10 18:55:47
【问题描述】:

我有一个查询,可以使用

获取特定日期的事件计数
select eventid_nbr, trunc(received_date, 'DD'), sentindicator, count (eventid_nbr) as count
from eventlog
where received_date >= to_date('2017-07-01','YYYY-MM-DD') and sentindicator = 'Y'
group by eventid_nbr, trunc(received_date, 'DD'), sentindicator
order by trunc(received_date, 'DD');

但是,我需要 x 天的最大计数,并按如下方式修改我的查询

select y.eventid_nbr, trunc(y.received_date, 'DD'), y.sentindicator, max(y.count)
from (select count(eventid_nbr) as count from eventlog) y
where y.received_date between to_date('2017-07-01','YYYY-MM-DD') and to_date('2017-07-03','YYYY-MM-DD') and y.sentindicator = 'Y'
group by y.eventid_nbr , trunc(y.received_date, 'DD'), y.sentindicator
order by trunc(y.received_date, 'DD');

执行结果

ORA-06553:PLS-306:调用“OGC_Y”时参数的数量或类型错误

为什么我会收到这个问题? Stack 也报告了类似的问题here,但我没有使用双引号。

【问题讨论】:

  • 您的新查询中的 y 仅包含一列 count,因此您不能引用 y.received_date 或任何其他 y 列。
  • @NetMage 我删除了列引用并尝试 select x, (select max(count) from (select count(y) as count from t)) from t where .... 脚本正在运行但我觉得我好像身处黑暗之中。有什么建议吗?
  • 您需要select 中的其他列值还是只需要计数的最大值?如果超过一天的最大计数相同,您希望发生什么?
  • @NetMage 除了 max(count(eventid_nbr)) 之外,我还想要 select 中的其他列值,但只需要 eventid_nbr 和 max(count(eventid_nbr))。如果两天有相同的计数恰好是最大值,则可以复制它们而不会丢失数据完整性。

标签: sql count max


【解决方案1】:

你需要找到 Max(Count()) 然后返回所有匹配的组/天:

select eventid_nbr, trunc(received_date, 'DD'), sentindicator, count (eventid_nbr) as count
from eventlog
where y.received_date between to_date('2017-07-01','YYYY-MM-DD') and to_date('2017-07-03','YYYY-MM-DD') and sentindicator = 'Y'
group by eventid_nbr, trunc(received_date, 'DD'), sentindicator
having count(eventid_nbr) = (select max(count)
                             from (select count(eventid_nbr) as count
                                   from eventlog
                                   where y.received_date between to_date('2017-07-01','YYYY-MM-DD') and to_date('2017-07-03','YYYY-MM-DD') and sentindicator = 'Y'
                                   group by eventid_nbr, trunc(received_date, 'DD'), sentindicator) )
order by trunc(received_date, 'DD');

【讨论】:

    猜你喜欢
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多