两个空白显示全部怎么加括号

select * from table where 1=1

(${if(len(a)==0,"","and num >= '"+a+"'")}

${if(len(b)==0,"","and num <= '"+b+"'")})

(${if(len(c)==0,"","or soc >= '"+c+"'")}

${if(len(d)==0,"","and soc <= '"+d+"'")})

a、b、c、d四个参数,要实现a、b两个参数不为空时,a=<num<=b;

c、d两个参数不为空时,c=<soc<=d;

四个参数都不问空时,a=<num<=b or c=<soc<=d,

这种逻辑用空白显示全部怎么写,求教!

我直接在两个参数外面加括号就出错了

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

select * from 

(select 10 as num,6 as soc ) aa

where 1=1

${if(len(a)==0,if(len(b)==0,"",""),"and ( num >= "+a+"  ")}

--

${if(len(b)==0,if(len(a)==0,"",")"),if(len(a)=0,"and ( num <= "+b+" ) ","and num <= "+b+" ) "))}

${if(len(c)==0,if(len(d)==0,"","and ("),if(len(a)=0&&len(b)=0,"and ( soc >= "+c+"  ","or ( soc >= "+c+"  "))}

${if(len(d)==0,if(len(c)==0,"",")"),if(len(c)==0," soc <= "+d+" )","and soc <= "+d+" )"))}

image.png

  • 392380857 392380857(提问者) 兄弟,你这个我好像看懂了,但是如果ab参数为空,cd参数有值得话,是不是就执行不了了
    2022-03-27 10:53 
  • 15922204585 15922204585 回复 392380857(提问者) 可以,你执行一下
    2022-03-27 10:55 
最佳回答
0
CD20160914Lv8专家互助
发布于2022-3-27 09:47

select * from table 

where 1=1

${if(len(a)>0&&len(b)>0&&len(c)>0&&len(d)>0,"and(num>='"+a+"' and num<='"+b+"') 

or (count>='"+c+"' and count<='"+d+"')",

if(len(a)>0&&len(b)>0," and num>='"+a+"' and num<='"+b+"'",

if(len(c)>0&&len(d)>0," and count>='"+c+"' and count<='"+d+"'","")))}

and name = '${name}' 

and zhiwu = '${zhiwu}'

image.png

image.png

image.png

image.png

  • 392380857 392380857(提问者) select * from table where 1=1 ${if(len(a)>0&&len(b)>0&&len(c)>0&&len(d)>0,\"and(num>=\'\"+a+\"\' and num<=\'\"+b+\"\') -------------or (count>=\'\"+c+\"\' and count<=\'\"+d+\"\')\", if(len(a)>0&&len(b)>0,\" and num>=\'\"+a+\"\' and num<=\'\"+b+\"\'\", if(len(c)>0&&len(d)>0,\" and count>=\'\"+c+\"\' and count<=\'\"+d+\"\'\",\"\")))} and name = \'${name}\' and zhiwu = \'${zhiwu}\' 我写减号那个or会导致 name、zhiwu的条件都失效。 我的回复为什么不能加图片、、、、
    2022-03-27 10:49 
  • CD20160914 CD20160914 回复 392380857(提问者) 你中间用什么减号?直接复制我的不行?加图片要在你是最上面提问的地方 编辑。。。再加图片。
    2022-03-27 11:04 
  • 392380857 392380857(提问者) 回复 CD20160914 我不是要写减号,是标记以下哪个位置,那个or会使name、zhiwu的条件都失效
    2022-03-27 12:36 
  • 3关注人数
  • 394浏览人数
  • 最后回答于:2022-3-27 09:47
    请选择关闭问题的原因
    确定 取消
    返回顶部