使用Oracle数据库的denodo服务器上未创建月份功能错误

问题描述

我试图显示总计(当前天与前一天)的差额,但是month函数在oracle中不起作用。我还使用denodo来运行此查询。我尝试添加提取功能以使其与月份配合使用,但似乎也无法正常工作。

pedics:

study id        date         total
RSCLS CA10001  2020-08-11    52
RSCLS CA10001  2020-08-10    52
ETDLD CA20302  2020-08-11    99
ERGKG CA34524  2020-08-11    31

查询:

select
  tt1.study,tt1.id,tt1.date,tt1.total,(tt1.total-ifnull(tt2.total,0)) as delta
from pedics tt1
  left outer JOIN pedics tt2 on tt1.total = tt2.total
    and month(tt1.date1)-month(tt2.date1)=1;

解决方法

请勿为此使用month()extract()!它不会在一月份上班。相反:

select tt1.study,tt1.id,tt1.date,tt1.total,(tt1.total - coalesce(tt2.total,0)) as delta
from pedics tt1 left outer join
     pedics tt2
     on tt1.total = tt2.total and
        trunc(tt1.date1,'MON') = trunc(tt2.date1,'MON') + interval '1' month;

但是,您的问题表明您只需要基于日期的上一行。所以,我想你真的想要:

select p.*,(p.total - lag(p.total,1,0) over (partition by study_id order by date)) as delta
from pedics p;
,

您可以尝试以下操作-使用extract(month from datecolumn)

select
  tt1.study,tt1.total-coalesce(tt2.total,0) as delta
from pedics tt1
  left outer JOIN pedics tt2 on tt1.total = tt2.total
    and extract(month from tt1.date)-extract(month from tt2.date)=1

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...