我有一个查询可以使用
获取特定日期的事件计数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,但我没有使用双引号。
答案 0 :(得分:0)
您需要找到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');