码迷,mamicode.com
首页 > 其他好文 > 详细

财务日报

时间:2016-01-12 10:01:29      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

create OR replace view region_ar_balance_2016 as
select dsr1.level0_sales_region_code "营销中心代码"
       ,dsr1.level0_sales_region_name "营销中心名称"
       ,dsr1.level2_sales_region_code "大区代码"
       ,dsr1.level2_sales_region_name"大区名称"
       ,dsr1.level3_sales_region_code "区域代码"
       ,dsr1.level3_sales_region_name "区域名称"
       ,round(sum(bal_amount_20141216)) "2014.12.16应收期初额"
       ,round(sum(sales_amount_2015)) "2015年送货额"
       ,round(sum(received_payment_2015)) "2015年回款额(1.1-12.31)"
       ,round(0) as "回款额(20160207)"
       ,round(sum(received_payment_2015)/decode((sum(bal_amount_20141216)+sum(sales_amount_2015)),0,-1,(sum(bal_amount_20141216)+sum(sales_amount_2015))),4)*100 || ‘%‘ "回款率1"
       ,round(0) as "回款率2"
       ,round(0) as "昨日应收余额"      
from BI_APD.APD_TB160111164221@BIDBPRD t
     ,bi_pdm.dim_sales_region@bidbprd dsr
     ,bi_pdm.dim_sales_region@bidbprd dsr1
WHERE dsr.level3_sales_region_name = t.region_name
and   dsr.level3_sales_region_name = dsr1.sales_region_name
AND   dsr1.sales_region_type = ‘KL_OM_QY‘
group by dsr1.level0_sales_region_name
         ,dsr1.level0_sales_region_code3
         ,dsr1.level2_sales_region_name
         ,dsr1.level2_sales_region_code
         ,dsr1.level3_sales_region_name
         ,dsr1.level3_sales_region_code
         
union all

SELECT dsr1.level0_sales_region_code "营销中心代码"
       ,dsr1.level0_sales_region_name "营销中心名称"
       ,dsr1.level2_sales_region_code "大区代码"
       ,dsr1.level2_sales_region_name"大区名称"
       ,dsr1.level3_sales_region_code "区域代码"
       ,dsr1.level3_sales_region_name "区域名称"
       ,round(0) as "2014.12.16应收期初额"
       ,round(0) as "2015年送货额"
       ,round(0) as "2015年回款额(1.1-12.31)"
       ,round(sum(amount_cny)/10000,2) "回款额(20160207)"
       ,round(0)|| ‘‘ as "回款率1"
       ,round(0) as "回款率2"
       ,round(0) as "昨日应收余额"
FROM bi_gdm.adt_ar_cash_receipts_f@bidbprd t
     ,bi_pdm.dim_sales_region@bidbprd dsr
     ,bi_pdm.dim_sales_region@bidbprd dsr1
WHERE dsr.level3_sales_region_name = t.region_name
and   dsr.level3_sales_region_name = dsr1.sales_region_name
AND   dsr1.sales_region_type = ‘KL_OM_QY‘
AND   day_wid >= ‘20160101‘ 
AND   day_wid < to_char(sysdate, ‘yyyymmdd‘)
AND   day_wid <= ‘20160207‘
group by dsr1.level0_sales_region_name
         ,dsr1.level0_sales_region_code
         ,dsr1.level2_sales_region_name
         ,dsr1.level2_sales_region_code
         ,dsr1.level3_sales_region_name
         ,dsr1.level3_sales_region_code
 
union all

SELECT dsr1.level0_sales_region_code "营销中心代码"
       ,dsr1.level0_sales_region_name "营销中心名称"
       ,dsr1.level2_sales_region_code "大区代码"
       ,dsr1.level2_sales_region_name "大区名称"
       ,dsr1.level3_sales_region_code "区域代码"
       ,dsr1.level3_sales_region_name "区域名称"
       ,round(0) as "2014.12.16应收期初额"
       ,round(0) as "2015年回款额(1.1-12.31)"
       ,round(0) as "2015年送货额"
       ,round(0) as "回款额(20160207)"
       ,round(0)|| ‘‘ as "回款率1"
       ,round(0) as "回款率2"
       ,round(sum(bal_amount)/10000,2)  "昨日应收余额"
FROM bi_pdm.rpt_ar_balance_a@bidbprd t
     ,bi_pdm.dim_sales_region@bidbprd dsr
     ,bi_pdm.dim_sales_region@bidbprd dsr1
where t.sales_region_wid = dsr.sales_region_wid
and   dsr.level3_sales_region_name = dsr1.sales_region_name
and   dsr1.sales_region_type = ‘KL_OM_QY‘
and   month_wid = to_char(sysdate,‘yyyymm‘)
group by dsr1.level0_sales_region_name
         ,dsr1.level0_sales_region_code
         ,dsr1.level2_sales_region_name 
         ,dsr1.level2_sales_region_code
         ,dsr1.level3_sales_region_name 
         ,dsr1.level3_sales_region_code;

注意点:1、字段名称和字段类型都必须一样;  (特别是合并字符串)

    2、表连接之间的条件,必须清晰;

做法:select字段和group by字段分别都必须一样;

财务日报

标签:

原文地址:http://www.cnblogs.com/yexiaoxin992/p/5123217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!