如何取上月数据

在数据库里月份的格式是202110这样的,我想取上月数据使用的是substr(month_date,1,6)=(substr(today(),1,6)-'1')

取不到数请问应该怎么写呢?

FineReport 用户x076327 发布于 2021-12-1 15:09 (编辑于 2021-12-1 15:29)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共4回答
最佳回答
1
luojian0323Lv7资深互助
发布于2021-12-1 15:11

where substr(month_date,1,7)=substr(current_date,1,7)

最佳回答
0
CD20160914Lv8专家互助
发布于2021-12-1 15:44(编辑于 2021-12-1 15:44)

oracle的数据库这样

to_char(trunc(trunc(sysdate, 'month') - 1, 'month'),'yyyymm')

不知道你的是什么数据库

最佳回答
0
yzm185688Lv2见习互助
发布于2021-12-3 16:24

strleft(create_date,7)  = strleft(to_date(months_sub(now(),1)),7)

最佳回答
0
用户e7w8d0325875Lv2见习互助
发布于2021-12-3 16:32(编辑于 2021-12-3 16:33)

to_date(substr(month_date,1,6))=to_date(today())-1 month

  • 5关注人数
  • 320浏览人数
  • 最后回答于:2021-12-3 16:33
    请选择关闭问题的原因
    确定 取消
    返回顶部