SQL问题

${if(org_shortname = '',"

SELECT business_m as 数值  

FROM table_A

WHERE index_code = 'CB005'

AND org_code = (SELECT distinct org_shortname FROM table_A

                WHERE org_code = 'GL001' AND STATS_MTH = '"+month+"' 

                ORDER BY org_shortname limit 1)

AND stats_mth = '"+ month +"'

","

SELECT business_m as 数值

FROM table_A

WHERE index_code = 'CB005'

AND org_shortname = '"+ org_shortname +"'

AND stats_mth = '"+ month +"'

")}

请大神帮看下上面这个sql,当参数org_shortname为空时,一直执行不出来,不知道是不是条件中的子查询格式有问题。

FineReport LTC朝 发布于 2024-4-28 09:38
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
1
LTC朝Lv6高级互助
发布于2024-4-28 10:08
子查询的字段写错了,code和name不匹配

最佳回答
0
用户k6280494Lv6资深互助
发布于2024-4-28 09:39

${if(len(org_shortname )=0,"

SELECT business_m as 数值  

FROM table_A

WHERE index_code = 'CB005'

AND org_code = (SELECT distinct org_shortname FROM table_A

                WHERE org_code = 'GL001' AND STATS_MTH = '"+month+"' 

                ORDER BY org_shortname limit 1)

AND stats_mth = '"+ month +"'

","

SELECT business_m as 数值

FROM table_A

WHERE index_code = 'CB005'

AND org_shortname = '"+ org_shortname +"'

AND stats_mth = '"+ month +"'

")}

  • 1关注人数
  • 150浏览人数
  • 最后回答于:2024-4-28 10:08
    请选择关闭问题的原因
    确定 取消
    返回顶部