参数问题写法,可以写sysdate吗,day1是变量

SELECT CALENDAR_DATE,SUB_SYSTEM ,LR_RATIO FROM  dwr.DWR_T_FAC_POWER_CONSUMPTION 

where 1=1

${if(to_date(day1,'yyyy-mm-dd'))=trunc(sysdate,'dd')," and LR_RATIO in (selectLR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION 

where CALENDAR_DATE = trunc(sysdate,'dd') -1)","

 and in LR_RATIO in (selectLR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION 

where CALENDAR_DATE = to_date(day1,'yyyy-mm-dd')"}

FineReport yzm107212 发布于 2023-10-26 13:23 (编辑于 2023-10-26 13:24)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
1
CD20160914Lv8专家互助
发布于2023-10-26 13:24(编辑于 2023-10-26 13:33)

你想实现什么效果。你的参数是什么?

SELECT CALENDAR_DATE,SUB_SYSTEM ,LR_RATIO FROM  dwr.DWR_T_FAC_POWER_CONSUMPTION 

where 1=1

${if(format(day1,'yyyy-MM-dd')=format(today(),"yyyy-MM-dd")," and LR_RATIO in (selectLR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION 

where CALENDAR_DATE = to_date('"+format(DATEDELTA(day1,-1),"yyyy-MM-dd")+"','yyyy-mm-dd')","

 and in LR_RATIO in (selectLR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION 

where CALENDAR_DATE = to_date('"+format(day1,"yyyy-MM-dd")+"','yyyy-mm-dd')")}

image.png

image.png

  • yzm107212 yzm107212(提问者) day1
    2023-10-26 13:24 
  • CD20160914 CD20160914 回复 yzm107212(提问者) 你为什么只判断天,而前面又是日期
    2023-10-26 13:25 
  • yzm107212 yzm107212(提问者) 当day1=当天,那取当天-1的数据,如果day1不等于当天,那就取day1的数据
    2023-10-26 13:26 
  • CD20160914 CD20160914 回复 yzm107212(提问者) 看上面的修改!!
    2023-10-26 13:33 
  • yzm107212 yzm107212(提问者) 根据你的方法改了下,实现了想要的数据,谢谢大佬!${if(format(day1,\'yyyy-MM-dd\')=format(today(),\"yyyy-MM-dd\"),\" select CALENDAR_DATE,SUB_SYSTEM,LR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION where CALENDAR_DATE = to_date(\'\"+format(DATEDELTA(day1,-1),\"yyyy-MM-dd\")+\"\',\'yyyy-mm-dd\')\",\" select CALENDAR_DATE,SUB_SYSTEM, LR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION where CALENDAR_DATE = to_date(\'\"+format(day1,\"yyyy-MM-dd\")+\"\',\'yyyy-mm-dd\')\")}
    2023-10-26 13:57 
最佳回答
1
snrtuemcLv8专家互助
发布于2023-10-26 13:26(编辑于 2023-10-26 13:28)

改成下面的试试

SELECT CALENDAR_DATE,SUB_SYSTEM ,LR_RATIO FROM  dwr.DWR_T_FAC_POWER_CONSUMPTION 

where 1=1

${if(format(day1,'yyyy-MM-dd')=format(today(),"yyyy-MM-dd")," and LR_RATIO in (selectLR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION 

where CALENDAR_DATE = trunc(sysdate,'dd') -1)","

 and in LR_RATIO in (selectLR_RATIO from dwr.DWR_T_FAC_POWER_CONSUMPTION 

where CALENDAR_DATE = to_date("+day1+",'yyyy-mm-dd')"}

  • 2关注人数
  • 213浏览人数
  • 最后回答于:2023-10-26 13:33
    请选择关闭问题的原因
    确定 取消
    返回顶部