惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
Netflix TechBlog - Medium
V
Visual Studio Blog
博客园 - Franky
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
量子位
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
V
V2EX
The Cloudflare Blog
月光博客
月光博客
Last Week in AI
Last Week in AI
雷峰网
雷峰网
WordPress大学
WordPress大学
博客园 - 【当耐特】
博客园 - 聂微东
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 左少白

oracle 找回DROP掉的表 求解,工作流点通过时,弹出窗口让用户录入审核意见 oracle 游标 c# 多态 sqlserver 按五分钟分组 c# 继承 查询行转列 SqlParameter序列化的问题 oracle oracle trunc (date,dd )函数 oracle 游标 对象集合转换为datatable 用C# 正则 提取HTML标签中的值? oracle decode 与 case when ,空的处理 oracle select for update sql1 Oracle Index 相關知識 玩转DevExpress.XtraGrid.view.gridview oracle索引 在Oracle中进行大小写不敏感的查询2
同期进度,完成率
左少白 · 2010-02-21 · via 博客园 - 左少白

PROCEDURE P_DailyReport

            (v_StatisticsDate IN varchar2, v_BranchFlag IN VARCHAR2,cur_name OUT t_cursor)

IS

   i_year  INTEGER :=0;--年份

   i_month INTEGER  :=0;--月份

   i_day   INTEGER  :=0;--天数

   i_monthdays INTEGER :=0;--本月天数

   i_alldays   INTEGER  :=0;--全年天数

   d_firstday DATE;--本月第一天

   d_yearfirstday DATE;--本年第一天

   i_pastdays INTEGER  :=0;--当年已过天数

   d_lastyearfirstday DATE;--去年第一天

   d_lasttoday DATE;--去年今天

   d_StatisticsDate DATE;

BEGIN

    i_year  :=to_number(substr(v_statisticsdate,1,4));

    i_month :=to_number(substr(v_statisticsdate,6,2));

    i_day   :=to_number(substr(v_statisticsdate,9,2));

    d_StatisticsDate:=to_date(v_StatisticsDate,'yyyy-mm-dd');

    --本月第一天,总天数

    SELECT MIN(thedate),MAX(theday)

      INTO d_firstday,i_monthdays

      FROM dim_date

     WHERE theyear=i_year AND themonth=i_month;

     --全年天数

     SELECT COUNT(1),MIN(thedate)

       INTO i_alldays,d_yearfirstday

       FROM dim_date

      WHERE theyear=i_year;

     --当年已过天数

     SELECT COUNT(1)

       INTO i_pastdays

       FROM dim_date

      WHERE theyear=i_year AND thedate<=d_StatisticsDate;

     --去年第一天

     SELECT MIN(thedate)

       INTO d_lastyearfirstday

       FROM dim_date

      WHERE theyear=i_year-1;

     --去年今天

     SELECT thedate

       INTO d_lasttoday

       FROM dim_date

      WHERE theyear=i_year-1 AND themonth=i_month AND theday=i_day;

OPEN cur_name FOR

     SELECT  c.branchabbr,d.TARGET,

             round(d.TARGET/i_alldays*i_monthdays,2) monthtarget, --月指标

             round(SUM(e.amount)/100000000,4) xshje,

             round(SUM(e.amount)/(d.TARGET/i_alldays*i_day*100000000),4),--当月进度

             round(SUM(f.amount)/100000000,4) ndxshje,

             round(SUM(f.amount)/(d.TARGET/i_alldays*i_pastdays*100000000),4),--年同期进度

             round(d.TARGET/i_alldays*i_monthdays-SUM(e.amount)/100000000,4),  --月度差额

             round(SUM(g.amount)/100000000,4),

             round((SUM(f.amount)- SUM(g.amount))/ SUM(g.amount),4)

       FROM ( SELECT a.branchabbr,a.branchflag,b.branchflag branchflag3

                FROM(SELECT branchabbr,branchflag

                       FROM t_jzt_common_branch

                      WHERE isactive=1

                        AND branchlevel=2 AND branchflag<>'ZDA' AND branchflag<>'FDY'

                     ) a

                INNER JOIN(SELECT branchflag,higherbranchflag

                             FROM t_jzt_common_branch

                            WHERE isactive=1 AND branchflag<>'ZDA'

                           )b ON a.branchflag=b.higherbranchflag

            ) c

       LEFT JOIN  t_report_TARGET d ON d.statisticsdate=i_year

                                    AND d.branchflag=c.branchflag

                                    AND d.TARGETType='销售指标'

       LEFT JOIN (SELECT branchflag,sum(amount) amount--月度

                    FROM t_bi_dailysalereport

                   WHERE orderdate >=d_firstday AND orderdate<=d_StatisticsDate

                   GROUP BY branchflag

                 ) e ON e.branchflag=c.branchflag3

       LEFT JOIN (SELECT branchflag,sum(amount) amount--年度

                    FROM t_bi_dailysalereport

                   WHERE orderdate>=d_yearfirstday AND orderdate<=d_StatisticsDate

                   GROUP BY branchflag

                 ) f ON f.branchflag=c.branchflag3

       LEFT JOIN (SELECT branchflag,sum(amount) amount --去年

                    FROM t_bi_dailysalereport

                   WHERE orderdate >=d_lastyearfirstday AND orderdate<=d_lasttoday

                   GROUP BY branchflag

                 )g ON g.branchflag=c.branchflag3

       GROUP BY c.branchabbr,d.TARGET

       ORDER BY c.branchabbr,d.TARGET;

END P_DailyReport;