如何取最近六个月的数据

select

'本月',a.值

from 

(

select by_income as  值 from app_db.vacompany_m_hy

where calmonth = translate(substr(current_date() , 1 ,7 ),'-','')

) as a

这是取本月的数据,请问我想改成取最近六个月的数据,应该怎么写呢?

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

select

'本月',a.值

from 

(

select by_income as  值 from app_db.vacompany_m_hy

where calmonth between  translate(substr(current_date() , 1 ,7 ),'-','')-6 and  translate(substr(current_date() , 1 ,7 ),'-','')

) as a

建议把translate换成 replace(substr(current_date() , 1 ,7 ),'-','')

transale好像无法把-替换掉的,影响条件判断

  • 2关注人数
  • 189浏览人数
  • 最后回答于:2021-11-23 16:26
    请选择关闭问题的原因
    确定 取消
    返回顶部