Orcal常用查询实例集合

本文的初衷主要是记录工作中碰到的一些查询实例,便于后续的工作参考从而提高效率。

一、A表拼接B表的数据,A、B两个表字段相同,当B表有数据时用B表的,否则用A表的。区分粒度为业务日期。

select z.fundid,
       z.busidate,
       z.cloumn1,
       z.cloumn2
  from tablea z
 where z.fundid in (fundids)
   and z.busidate between begindate and enddate
   and z.fundid || z.busidate not in
       (select t.fundid || t.busidate as unioncode
          from tableab t
         group by t.fundid || t.busidate)
union
select t.fundid,
       t.busidate,
       '89' || t.cloumn1,
       t.cloumn2
  from tableab t
 where t.fundid in(fundids)
   and t.busidate between begindate and enddate
原文地址:https://www.cnblogs.com/zeussbook/p/14151668.html