orcal查询12个月份数据,没有则用0补充

根据薪酬表 获取 12个月应发工资,没有则用0补充


SELECT a.calcmonthlist  年月, nvl(b.totalsalary, 0) 应发工资
  FROM (SELECT TO_CHAR(ADD_MONTHS(TO_DATE('2019-01', 'yyyy-MM'), ROWNUM - 1),
                       'yyyyMM') AS calcmonthlist
          FROM DUAL
        CONNECT BY ROWNUM <=
                   months_between(to_date('201912', 'yyyyMM'),
                                  to_date('201901', 'yyyyMM')) + 1) a
  left join (select c.calcmonth, c.totalsalary
               from prpssalary c
              where c.usercode = '175527767') b
    on a.calcmonthlist = b.calcmonth
 order by a.calcmonthlist;

效果图如下:

 

orcal查询12个月份数据,没有则用0补充_第1张图片

你可能感兴趣的:(#,orcal)