怎末使PRO_AMO字段后面跟上上年年初年末的金额

image.png

SQL ROBOT 发布于 2022-11-7 12:04
1min目标场景问卷 立即参与
回答问题
悬赏:0 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2022-11-7 12:36

image.png

是要年初还是年末?已上年年初为例

SELECT a.*,b.pro_amo as 年初,c.pro_amo as 年末 FROM tablea a

left join (

select * from tablea where substr(pro_date,6,2)='01'

) b on substr(a.pro_date,1,4)=substr(b.pro_date,1,4)

left join (

select * from tablea where substr(pro_date,6,2)='12'

) c on substr(a.pro_date,1,4)=substr(c.pro_date,1,4)-1

最佳回答
0
snrtuemcLv8专家互助
发布于2022-11-7 12:25

这个不是有写了吗,你要年初年末稍微修改下

SELECT a.*,b.pro_amo as 年初,c.pro_amo as 年末 FROM tablea a

left join (

select * from tablea where substr(pro_date,6,2)='01'

) b on substr(a.pro_date,1,4)=substr(b.pro_date,1,4)

left join (

select * from tablea where substr(pro_date,6,2)='12'

) c on substr(a.pro_date,1,4)=substr(c.pro_date,1,4)

  • 2关注人数
  • 232浏览人数
  • 最后回答于:2022-11-7 12:36
    请选择关闭问题的原因
    确定 取消
    返回顶部