比较plsql中的数据和日期

时间:2017-06-07 11:30:22

标签: sql plsql

我有一张桌子:

date_stmp     ticker_name    a_clos_prc   b_clos_prc
05/20/17      APPL           $300.60      $300.60
05/21/17      APPL                        $300.61

如果b_clos_prc缺少数据且a_clos_prc有数据,是否有办法检查IF b_clos_prc是否与前一天相同?

因此,对于该示例,结果将如下所示:

 date_stmp   ticker_name     a_clos_prc   b_clos_prc   Diff
 05/20/17    APPL            $300.60      $300.60
 05/21/17    APPL                         $300.61     +0.01 

我被困在如何为此提出逻辑。

1 个答案:

答案 0 :(得分:0)

select *
  from table a2, table a1
 where trunc(a1.date_stmp) - 1 = trunc(a2.date_stmp)
   and (a1.a_clos_prc = a2.b_clos_prc  or (a1.a_clos_prc is null and  a2.b_clos_prc is null ))