选择不同下拉框的值,执行不同的sql,sql中有参数,不知道语法怎么写,那位大神帮忙写一下

控件名称:bblx0

控件值:A类,B类

第一段sql select   count(*) from  syreport.dm_A  where 1=1  and month_id between '${starttime2}' and '${endtime2}'  -- 考核周期   -- 客户号    ${if(len(clientid2) == 0,"","and client_id_later in ('" + replace(clientid2,",","','") + "')")}      第二段sql select  count(*)from syreport.dm_B where 1=1  and month_id between '${starttime2}' and '${endtime2}'  -- 考核周期   -- 客户号    ${if(len(clientid2) == 0,"","and client_id_later in ('" + replace(clientid2,",","','") + "')")}

奥特曼大王之王者归来 发布于 2021-7-6 19:00
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
luojian0323Lv7资深互助
发布于2021-7-6 19:05(编辑于 2021-7-6 19:07)

${if(bblx0='A类',"select   count(*) from  syreport.dm_A  where 1=1  and month_id between '"+starttime2+"' and '"+endtime2+"'",if(bblx0="B类","select  count(*)from syreport.dm_B where 1=1  and month_id between '"+starttime2+"' and '"+endtime2+"'",""))}

${if(len(clientid2) == 0||len(bblx0)==0,"","and client_id_later in ('" + replace(clientid2,",","','") + "')")}

最佳回答
0
liu.yangLv2初级互助
发布于2021-7-6 19:13(编辑于 2021-7-6 19:17)

如果数据库支持  with  tmp as ()  这样的写法的话  可以  with sql1 as (第一段SQL),sql2 as (第二段SQL)

然后  if 根据参数 选择 select  * from  sql1  还是  select  * from sql2

  • 3关注人数
  • 417浏览人数
  • 最后回答于:2021-7-6 19:17
    请选择关闭问题的原因
    确定 取消
    返回顶部