帆软分组求和不能跨月

如下图所示,5月、6月均有数据,但是当时间调整到两个月的时候,数据显示不出来。弄了好久,实在不知道哪出问题了。

image.pngimage.pngimage.png

with aa as 

(SELECT  acct_code,cost_center,ST_NO as grade,MAT_NO,substr(mat_no,1,8) as pono,MAT_ACT_WIDTH as size,MAT_ACT_WT as weight,IN_MAT_NO,IN_MAT_WT,app_throw_ai_key,substr(apcod_date_sumnum,3,14) as ap_time,substr(close_mon,1,6) as close_mon

FROM "BG00MSCB00"."T_DWD_FACT_CBAI_TACAIWBLG" where  cost_center in ('ABEC','ABEG')  ),

a as (select aa.* from aa where close_mon>='${日期起}' AND close_mon<='${日期止}' ),

a1 as (select * from (select distinct pono,cost_center,grade,ap_time,row_number()over(partition by pono,cost_center order by ap_time desc  ) rn

from a  where ACCT_CODE=01  order by pono,cost_center,ap_time) where rn=1),

b as (select  pono,cost_center,sum(weight) as LB_total from a  where ACCT_CODE=01 group by pono,cost_center),

c as (

select pono,sum(weight) as ladle from a where ACCT_CODE='31' group by pono

 ),

d as (select pono,-sum(weight) as sp from a where substr(app_throw_ai_key,23,2)='31' group by pono),

e as (select distinct a.close_mon,a.pono,b.cost_center,b.LB_total,d.sp,c.ladle as ladle_c from a left join b on a.pono=b.pono left join c on a.pono=c.pono left join d on a.pono=d.pono  where a.pono<>''  order by pono)

select e.*,a1.grade,(case when e.cost_center is null then 'ABEG' else e.cost_center end) as cost_center1 from e left join a1 on e.pono=a1.pono and e.cost_center=a1.cost_center order by pono

image.pngimage.png

FineReport 帆软用户21wlka79tN 发布于 2024-7-12 18:11 (编辑于 2024-7-12 18:26)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
CovidLv3高级互助
发布于2024-7-12 18:15

SQL贴出来 你怎么写的?

数据库中数据格式和控件的数据格式是否一致

  • 帆软用户21wlka79tN 帆软用户21wlka79tN(提问者) 看补充问题
    2024-07-12 18:26 
  • 帆软用户21wlka79tN 帆软用户21wlka79tN(提问者) 我试了很多情况,大概率是日期格式或者别的跟日期相关的出错了。我日期函数都是用的MONTHDELTA(today(),-1)
    2024-07-12 18:31 
  • Covid Covid 回复 帆软用户21wlka79tN(提问者) 支付串用比较符合(大于,大于等于,小于,小于等于)最容易出问题。你在close_mon后面拼接个01,然后转化成标准的yyyy-MM-01的格式,同样控件也设置成yyyy-MM-01,这样就可以了
    2024-07-12 18:46 
  • 帆软用户21wlka79tN 帆软用户21wlka79tN(提问者) 回复 Covid 谢谢大哥,知道哪错了,日期起和日期止搞反了,我去!
    2024-07-15 08:54 
  • 1关注人数
  • 116浏览人数
  • 最后回答于:2024-7-12 18:26
    请选择关闭问题的原因
    确定 取消
    返回顶部