我有一张桌子:
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
我被困在如何为此提出逻辑。
答案 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 ))