同期时间关联问题

我想把当月和同期当月的数值在同一行显示image.png,但是显示不出来去年当月的数值

SELECT 

T1.month_id,T1.当月收入,T2.去年收入

FROM

(

select month_id, nonoil_income as "当月收入" from ywgl_csrq where month_id between substr(current_date() , 1 ,4)||'01' and  translate(substr(current_date() , 1 ,7),'-','')

) t1

left join

(

select month_id, nonoil_income as "去年收入" from ywgl_csrq where month_id between substr(monthdelta(today(),-12), 1 ,4)||'01' and  translate(substr(monthdelta(today(),-12) , 1 ,7),'-','')

) t2

on t1.month_id = t2.month_id 

order by month_id

FineReport 用户x076327 发布于 2021-11-30 13:58
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
1
小木木Lv5见习互助
发布于2021-11-30 14:04(编辑于 2021-11-30 14:05)

SELECT 

T1.month_id,T1.当月收入,T2.去年收入

FROM

(

select month_id, nonoil_income as "当月收入" from ywgl_csrq where month_id between substr(current_date() , 1 ,4)||'01' and  translate(substr(current_date() , 1 ,7),'-','')

) t1

left join

(

select month_id, nonoil_income as "去年收入" from ywgl_csrq where month_id between substr(monthdelta(today(),-12), 1 ,4)||'01' and  translate(substr(monthdelta(today(),-12) , 1 ,7),'-','')

) t2

on substr(t1.month_id,5,6) = substr(t2.month_id ,5,6)

order by month_id

最佳回答
1
丶尛伟Lv6初级互助
发布于2021-11-30 14:00

month_id不可能相等的啊,今年的日期怎么会等于去年的日期呢

  • 用户x076327 用户x076327(提问者) 那我想把日期关联起来,那应该怎么写呢
    2021-11-30 14:02 
  • 丶尛伟 丶尛伟 回复 用户x076327(提问者) 你是什么数据库啊
    2021-11-30 14:03 
  • 3关注人数
  • 344浏览人数
  • 最后回答于:2021-11-30 14:05
    请选择关闭问题的原因
    确定 取消
    返回顶部