写sql公式时怎么写参数为空时后面还有加上groupby呀

写sql公式时怎么写参数为空时后面还有加上group by 呀

SQL("frdemo","SELECT a.bm FROM org_info a LEFT JOIN (SELECT bm, length(bm) len, dj FROM org_info WHERE 1=1 "+if(len(shi) == 0,"","and bm = '" +shi + "'") GROUP BY bm, dj) t1 ON 1 = 1 WHERE substr( a.bm, 1, len - 6 )= substr( t1.bm, 1, len - 6 )) ",1)

FineReport 123木头人1 发布于 2022-7-28 10:49 (编辑于 2022-7-28 11:01)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2022-7-28 10:51(编辑于 2022-7-28 10:52)

"WHERE 1 = 1 "+if(len(shi) == 0," GROUP BY bm, dj"," AND wgbm = '" +shi + "' GROUP BY bm, dj")

  • 123木头人1 123木头人1(提问者) where 前面就要加双引号了吗
    2022-07-28 10:55 
  • Z4u3z1 Z4u3z1 回复 123木头人1(提问者) 你的这个SQL是写在数据集里面,还单元格公式里面?我理解的是单元格里面,我示例里面 where前面的双引号不要,你的应该已经有了
    2022-07-28 10:59 
  • 123木头人1 123木头人1(提问者) 回复 Z4u3z1 写在sql公式里面的,我已经把整段帖上来了,麻烦看看
    2022-07-28 11:03 
  • Z4u3z1 Z4u3z1 回复 123木头人1(提问者) SQL(\"frdemo\",\"SELECT a.bm FROM org_info a LEFT JOIN (SELECT bm, length(bm) len, dj FROM org_info WHERE 1=1 \"+if(len(shi) == 0,\" GROUP BY bm, dj\",\"and bm = \'\" +shi + \"\' GROUP BY bm, dj\")+\") t1 ON 1 = 1 WHERE substr( a.bm, 1, len - 6 )= substr( t1.bm, 1, len - 6 )\",1) 斜杠是系统自己加的,请删除
    2022-07-28 11:13 
最佳回答
0
snrtuemcLv8专家互助
发布于2022-7-28 10:51(编辑于 2022-7-28 11:06)

SQL("frdemo","SELECT a.bm FROM org_info a LEFT JOIN (SELECT bm, length(bm) len, dj FROM org_info WHERE 1=1 "+if(len(shi) == 0,"","and bm = '" +shi + "'")+"GROUP BY bm, dj) t1 ON 1 = 1 WHERE substr( a.bm, 1, len - 6 )= substr( t1.bm, 1, len - 6 ))",1)

  • 123木头人1 123木头人1(提问者) sql公式里面,一直写不对
    2022-07-28 10:53 
  • snrtuemc snrtuemc 回复 123木头人1(提问者) 整个拷贝出来看看
    2022-07-28 10:58 
  • 123木头人1 123木头人1(提问者) 回复 snrtuemc SQL(\"frdemo\",\"SELECT a.bm FROM org_info a LEFT JOIN (SELECT bm, length(bm) len, dj FROM org_info WHERE 1=1 \"+if(len(shi) == 0,\"\",\"and bm = \'\" +shi + \"\'\") GROUP BY bm, dj) t1 ON 1 = 1 WHERE substr( a.bm, 1, len - 6 )= substr( t1.bm, 1, len - 6 )) \",1)
    2022-07-28 11:00 
  • 123木头人1 123木头人1(提问者) 回复 snrtuemc 麻烦看看,一直也不对,谢谢啦
    2022-07-28 11:00 
  • snrtuemc snrtuemc 回复 123木头人1(提问者) 看下修改答案,看看可以吗
    2022-07-28 11:06 
  • 2关注人数
  • 304浏览人数
  • 最后回答于:2022-7-28 11:06
    请选择关闭问题的原因
    确定 取消
    返回顶部