通过参数的不同值编写不同的sql

当传来的参数的值不同时,执行不同的查询sql,该如何写,如下:

select xxx from xxx where xxx

and _________________________________________________________

条件如下:

当参数 'cx' = '调小'时,cx not in (select cx from xxx) [一个子查询]

当参数 'cx'!= '调小'时,cx = 传来的参数 cx

请问横线处该如何填写

FineReport yzm238913 发布于 2024-4-16 15:05
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
snrtuemcLv8专家互助
发布于2024-4-16 15:08(编辑于 2024-4-16 15:40)

select xxx from xxx where xxx

${if(cx='调小',"and cx not in (select cx from xxx)"," and cx ='"+cx+"'")}

===========

select xxx from xxx where xxx

${if(cx='调小',"and cx not in (select cx from xxx where 字段='"+cx+"')"," and cx ='"+cx+"'")}

  • yzm238913 yzm238913(提问者) 子查询后面select cx from xxx where cj = \"${cj}\" 这个该怎么写,cj也是一个参数
    2024-04-16 15:38 
  • snrtuemc snrtuemc 回复 yzm238913(提问者) 这个也是拼接,但是你是=调小,那不直接等写死一样啊,其他参数参考修改答案
    2024-04-16 15:40 
最佳回答
0
Z4u3z1Lv6专家互助
发布于2024-4-16 15:08

${if(cx="调小","select xxx from xxx where cx not in (select cx from xxx) ","sselect xxx from xxx where cx = 传来的参数 cx")}

最佳回答
0
菜鸟007号Lv5见习互助
发布于2024-4-16 15:10

where ${if(len(cx) == '调小'," and  cx not in (select cx from xxx)  "," and cx = '" + cx + "'")}

  • 3关注人数
  • 127浏览人数
  • 最后回答于:2024-4-16 15:40
    请选择关闭问题的原因
    确定 取消
    返回顶部