计算表里面时间差

image.png

select sum(sell_fee)sell_fee ,sc_no,depart_no from thz_dp_sc_income_m where 1=1 
and sell_fee !=0
and to_date(cyear||'-'||cmonth,'yyyy-mm') <=to_date('${years}-${months}','yyyy-mm')
group by sc_no,depart_no

请问怎么计算时间控件选中之前的数。比如我要看2019年5月之前得数,我本身是将年月拼接起来小于时间控件值,但是好像不行

吴浩 发布于 2019-5-14 14:29 (编辑于 2019-5-14 14:30)
1min目标场景问卷 立即参与
回答问题
悬赏:4 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
axingLv6专家互助
发布于2019-5-14 14:53

改成这样:to_date('${years+"-"+months}','yyyy-mm')

blob.png

  • 吴浩 吴浩(提问者) 这不是重复时间控件值了吗。上面是数据列名称吗。cyear,cmonth
    2019-05-14 14:57 
  • axing axing 回复 吴浩(提问者) 下面那句是你原来的,改成上面那句
    2019-05-14 15:03 
  • 吴浩 吴浩(提问者) select sum(sell_fee)sell_fee ,sc_no,depart_no from thz_dp_sc_income_m where 1=1 and sell_fee !=0 and to_date(cyear||\'-\'||cmonth,\'yyyy-mm\') <=to_date(\'${years+\"-\"+months}\',\'yyyy-mm\') group by sc_no,depart_no 谢谢,你的答案是对的
    2019-05-14 15:10 
最佳回答
0
baidnxLv1见习互助
发布于2019-5-14 14:37

时间控件是YYYY-MM-DD格式 你也得是这个格式?还是把后面参数改成 ${years}+'-'+${months} 或者用字符串拼接函数 concat(${years},'-',${months})

  • 吴浩 吴浩(提问者) 忘说了,我的是Oracle。直接拼接也可以
    2019-05-14 14:42 
最佳回答
0
KerydiaLv5中级互助
发布于2019-5-14 15:04

to_date(cyear||'-'||cmonth,'yyyy-mm') <=to_date('${years}-${months}','yyyy-mm')

改成

to_date(cyear||'-'||cmonth,'yyyy-mm') <=to_date('${years}'||'-'||'${months}','yyyy-mm')

cyear||'-'||cmonth<='${years}'||'-'||'${months}'

  • 4关注人数
  • 509浏览人数
  • 最后回答于:2019-5-14 15:04
    请选择关闭问题的原因
    确定 取消
    返回顶部