如何实现本期同期的趋势分析

31W4`VBX`6R)54]@YZQ$4O2.png

3[@_X`D~5FH`MY3KL(L0WNR.png

9@`{3BQ7H~DO]@T~(PDRSGO.png


【本期sql】

select  

 ${if(RG_REPORT_TYPE=="month", 

        " a.tongjirq as 实际日期, to_char(to_date(tongjirq,'yyyymmdd'),'dd') as 日期, ",

        " a.tongjiyf as 实际日期, a.tongjiyf as 日期, "

    )}

    sum(a.RENYUANSHU) as 人员数_本期,

    0 as 人员数_同期

 ${if(RG_REPORT_TYPE=="month", " from REPORT_V_RENLIZY a where a.tongjirq between to_char(to_date('"+P_YEARMONTH+"-01','yyyy-mm-dd'),'yyyymmdd') and to_char(last_day(to_date('"+P_YEARMONTH+"','yyyy-mm')),'yyyymmdd')", "")}

${if(RG_REPORT_TYPE=="quarter", " from REPORT_V_RENLIZY_m a where a.tongjiyf BETWEEN '"+P_YEAR+""+P_QUARTER+"' AND TO_CHAR(add_months(to_date('"+P_YEAR+"-"+P_QUARTER+"','yyyy-mm'),3)-1,'YYYYMM')", "")}

${if(RG_REPORT_TYPE=="year", " from REPORT_V_RENLIZY_m a where a.tongjiyf like '"+P_YEAR+"%'", "")}

${if(len(P_YILIAOJG)==0,"","AND a.YILIAOJGDM = '"+P_YILIAOJG+"'")}

${if(len(P_KESHIDM)==0, "", " and a.keshidm in ('" + P_KESHIDM + "')")}

${if(RG_REPORT_TYPE=="month", " group by a.tongjirq order by a.tongjirq "," group by a.tongjiyf order by a.tongjiyf ")}

【同期sql】

select  

   ${if(RG_REPORT_TYPE=="month", 

        " a.tongjirq as 实际日期, to_char(to_date(tongjirq,'yyyymmdd'),'dd') as 日期, ",

        " a.tongjiyf as 实际日期, a.tongjiyf as 日期, "

    )}

    0 as 人员数_本期,

     sum(a.RENYUANSHU) as 人员数_同期


 ${if(RG_REPORT_TYPE=="month", " from REPORT_V_RENLIZY a where a.tongjirq between to_char(add_months(to_date('"+P_YEARMONTH+"-01','yyyy-mm-dd'),-12),'yyyymmdd') and to_char(add_months(last_day(to_date('"+P_YEARMONTH+"','yyyy-mm')),-12),'yyyymmdd')", "")}

${if(RG_REPORT_TYPE=="quarter", " from REPORT_V_RENLIZY_m a where a.tongjiyf BETWEEN  to_char(add_months(to_date( '"+P_YEAR+""+P_QUARTER+"','yyyymm'),-12) ,'yyyymm')AND  TO_CHAR(add_months(to_date('"+P_YEAR+"-"+P_QUARTER+"','yyyy-mm'),-12+3)-1,'YYYYMM')", "")}

${if(RG_REPORT_TYPE=="year", " from REPORT_V_RENLIZY_m a where a.tongjiyf like '"+(TOINTEGER(P_YEAR)-1)+"%'", "")}

${if(RG_REPORT_TYPE=="month", " group by a.tongjirq order by a.tongjirq "," group by a.tongjiyf order by a.tongjiyf ")}


FineReport 田梦语323 发布于 2020-3-31 17:44 (编辑于 2020-4-1 09:07)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
田梦语323Lv2见习互助
发布于2020-4-30 11:11

sql问题,修改了

  • 0关注人数
  • 447浏览人数
  • 最后回答于:2020-4-30 11:11
    请选择关闭问题的原因
    确定 取消
    返回顶部