上月数据

to_char(r.PROD_DATE, 'yyyy-mm') ='${format(reportYearMonth, 'yyyy-MM')}'

这取的是当月数据,如何取上月数据

FineReport SQL 用户G2632943 发布于 2022-12-1 09:37
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
weibwLv7高级互助
发布于2022-12-1 09:38

to_char(r.PROD_DATE, 'yyyy-mm') ='${format(MONTHDELTA(reportYearMonth,-1), 'yyyy-MM')}'

最佳回答
0
用户72377877Lv4见习互助
发布于2022-12-1 10:23

https://help.fanruan.com/finereport/doc-view-876.html这里有各种日期函数

sql取月初月底、季年周等日期范围

select getdate() as 当日,

dateadd(dd,-1,getdate()) as 昨日, 

dateadd(dd,-2,getdate()) as 前日,

dateadd(dd,-datepart(dd,getdate())+1,getdate()) as 月初,

dateadd(dd,-day(getdate())+1,getdate()) as 月初_写法2,

dateadd(day,-1,dateadd(month,1,dateadd(dd,-datepart(dd,getdate())+1,getdate()))) as 月底,--月初加1月减一天

dateadd(dd,-day(dateadd(month,1,getdate())),dateadd(month,1,getdate())) as 月底_写法2,--加1月减去下月的天数  

--dateadd(day,-day(getdate()),dateadd(month,1,getdate())) as 月底,2018-01-31取到的是2018-01-28 22:02:13.183

dateadd(dd,-day(dateadd(month,1,getdate()))+1,dateadd(month,1,getdate())) as 下月初,

dateadd(dd,-day(dateadd(month,2,getdate())),dateadd(month,2,getdate())) as 下月底, 

dateadd(quarter,datediff(quarter,0,getdate())-1,0) as 上季初,

dateadd(quarter,datediff(quarter,0,getdate()),-1) as 上季末,

dateadd(quarter,datediff(quarter,0,getdate()),0) as 季初,

dateadd(quarter,1+datediff(quarter,0,getdate()),-1) as 季末,

dateadd(quarter,1+datediff(quarter,0,getdate()),0) as 下季初,

dateadd(quarter,2+datediff(quarter,0,getdate()),-1) as 下季末,

dateadd(month,datediff(month,0,getdate())-1,0) as 上月初,

dateadd(dd,-day(dateadd(month,-1,getdate()))+1,dateadd(month,-1,getdate())) as 上月初_写法2,

dateadd(day,-1,dateadd(day,1-datepart(day,getdate()),getdate())) as 上月底,

dateadd(dd,-day(getdate()),getdate()) as 上月底_写法2,  

dateadd(month,datediff(month,0,getdate())-2,0) as 前月初,

dateadd(day,-1,dateadd(month,datediff(month,0,getdate())-1,0)) as 前月底,

dateadd(year,datediff(year,0,getdate()),0) as 年初,

dateadd(year,datediff(year,-1,getdate()),-1) as 年底,

dateadd(year,datediff(year,0,getdate())-1,0) as 去年年初,

dateadd(year,datediff(year,0,getdate()),-1) as 去年年末,

dateadd(year,1+datediff(year,0,getdate()),0) as 明年年初,

dateadd(year,1+datediff(year,-1,getdate()),-1) as 明年年末,

dateadd(weekday,1-datepart(weekday,getdate()),getdate()) as 周初,

dateadd(day,7,dateadd(weekday,-datepart(weekday,getdate()),getdate())) as 周底,

--dateadd(week,datediff(week,-1,getdate()),-1) as 周底,

dateadd(week,-1,dateadd(day,1-datepart(weekday,getdate()),getdate())) as 上周初,

dateadd(weekday,-datepart(weekday,getdate()),getdate()) as 上周底,

dateadd(week,-2,dateadd(day,1-datepart(weekday,getdate()),getdate())) as 前周初,

dateadd(week,-1,dateadd(day,-datepart(weekday,getdate()),getdate())) as 前周底

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