sqlwhere后加if参数形式怎么写

怎么在left里面的where加if

select sum(num) num

from dm a

left join (SELECT ono,type FROM dm_cus where(如果type参数为空,type is null,type) GROUP BY ono,type ) b

on b.ono = a.ono

where data_date>= '${startTime}' AND data_date<='${endTime}'

${if(len(type)=0,"","and type in ('"+type+"')")}

FineReport 帆软用户CYJXJ 发布于 2023-9-25 13:34
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2023-9-25 13:58

select sum(num) num

from dm a

left join (SELECT ono,type FROM dm_cus where 1=1 ${IF(LEN(type)==0," AND type IS NULL"," AND TYPE IN('"+type+"')")} GROUP BY ono,type ) b

on b.ono = a.ono

where data_date>= '${startTime}' AND data_date<='${endTime}'

${if(len(type)=0,"","and type in ('"+type+"')")}

最佳回答
0
用户k6280494Lv6资深互助
发布于2023-9-25 13:51(编辑于 2023-9-25 13:53)

怎么在left里面的where加if

select sum(num) num

from dm a

left join (SELECT ono,type FROM dm_cus where 1=1 ${if(len(type)=0,"","and type in ('"+type+"')")} GROUP BY ono,type ) b

on b.ono = a.ono

where data_date>= '${startTime}' AND data_date<='${endTime}'

${if(len(type)=0,"","and type in ('"+type+"')")}

image.png

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