在计算Oracle DB上的保留时,我写了这段代码:
select
sessions.sessionDate ,
count(distinct sessions.visitorIdd) as active_users,
count(distinct futureactivity.visitorIdd) as retained_users,
count(distinct futureactivity.visitorIdd) / count(distinct sessions.visitorIdd)::float as retention
FROM sessions
left join sessions futureactivity on
sessions.visitorIdd=futureactivity.visitorIdd
and sessions.sessionDate = futureactivity.sessionDate - interval '3' day
group by 3;
但是我总是得到错误:“ORA-00923:mot-cléFRESSabsentàl'inclacementprévu”(ORA-00923 FROM keyword not found not expected) 你能帮帮我们吗?
答案 0 :(得分:1)
Oracle无法识别Postgres的::
语法,因此它抱怨在预期的地方找不到丢失的FROM
关键字。
使用强制转换:
count(distinct futureactivity.visitorIdd) / cast(count(distinct sessions.visitorIdd) as float) as retention
答案 1 :(得分:0)
这是一个更多" Oracle"编写查询的方式:
select s.sessionDate ,
count(distinct s.visitorIdd) as active_users,
count(distinct fs.visitorIdd) as retained_users,
count(distinct fs.visitorIdd) / count(distinct s.visitorIdd) as retention
from sessions s left join
sessions fs
on s.visitorIdd = fs.visitorIdd and
s.sessionDate = fs.sessionDate - interval '3' day
group by s.sessionDate
order by s.sessionDate;
注意:
group by
应包含列名称,实际上是" 1",而不是" 3"。order by
,因为结果将是一个不确定的顺序。