where条件为空查询全部,不为空按条件查询

我们在做权限的设置,主要通过传用户id的参数,筛选出公司
a为主表:含用户id,公司名称,b为权限对应表:含字段用户id,公司名称,
实现逻辑是sql写  select xxxx  from a where 公司名称  in  (select 公司名称  from   b  where 用户id={传参})
问题:由于提供的权限表中用户有查看全部公司的权限,但公司名称value值为全部,,sql 无法处理

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

select xxxx  from a where 1=1

${if("select 公司名称  from   b  where 用户id="+传参="全部","","and 公司名称  in  (select 公司名称  from   b  where 用户id="+传参))}

最佳回答
0
luojian0323Lv7资深互助
发布于2021-1-10 14:42
select xxxx  from a where 1=1

${if("select 公司名称  from   b  where 用户id='"+传参+"'='全部'","","and 公司名称  in  (select 公司名称  from   b  where 用户id='"+传参+"')")}


最佳回答
0
zsh331Lv8专家互助
发布于2021-1-11 12:54
select x  from a where 1=1 ${if(sql("数据连接名","select 公司名称  from   b  where 用户id='"+传参+"'",1,1)='全部',""," and 公司名称  in (select 公司名称  from   b  where 用户id='"+传参+"')")}

------------------

  • 5关注人数
  • 1268浏览人数
  • 最后回答于:2021-1-11 12:54
    请选择关闭问题的原因
    确定 取消
    返回顶部