用了临时表关联主查询,finereport报错,sql语句在navicat上可以正常执行


FineReport cipay 发布于 2018-12-28 10:26 (编辑于 2018-12-28 10:26)
1min目标场景问卷 立即参与
回答问题
悬赏:4 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
4
axingLv6专家互助
发布于2018-12-28 10:31

数据查询不支持drop和create语法

可以先在数据库创建存储过程再在这里执行

  • cipay cipay(提问者) 好吧
    2018-12-28 10:34 
  • axing axing 回复 cipay(提问者) 分号;也不支持
    2018-12-28 10:36 
  • cipay cipay(提问者) drop TEMPORARY table if exists MONTH_TABLE; CREATE TEMPORARY TABLE MONTH_TABLE(MONTH_NUM VARCHAR(10)) SELECT DISTINCT DATE_FORMAT(ld.date,\'%Y-%m\') AS MONTH_NUM FROM lab_dips AS ld; drop TEMPORARY table if exists tmp_table; CREATE TEMPORARY TABLE tmp_table SELECT DISTINCT ld.sales_organization_id AS organizationid, so.name AS name FROM lab_dips AS ld LEFT JOIN sales_organization AS so ON ld.sales_organization_id=so.id WHERE ld.sales_organization_id is not NULL GROUP BY organizationid; SELECT mm.mon,mm.name,IFNULL(t.counts,\'0\') AS counts FROM (SELECT mt.MONTH_NUM AS mon, tmp.name AS name -- IF(t.months=mt.MONTH_NUM AND tmp.name=t.organization,t.counts,\'0\') -- CASE -- WHEN t.months=mt.MONTH_NUM AND tmp.name=t.organization THEN t.counts ELSE \'0\' END AS counts -- ,t.counts AS counts FROM MONTH_TABLE mt,tmp_table tmp) AS mm LEFT JOIN ( SELECT DATE_FORMAT(ld.date,\'%Y-%m\') AS months, so.name AS organization, COUNT(ldd.id) AS counts FROM lab_dips AS ld LEFT JOIN lab_dip_details AS ldd ON ldd.lab_dip_id = ld.id LEFT JOIN sales_organization AS so ON ld.sales_organization_id=so.id -- LEFT JOIN t_account AS ta ON ta.FID = ld.creator_id WHERE ld.deleted_at IS NULL -- ${if(len(startmonth)==0,\"\", \" AND date_format(ld.date,\'%Y-%m\')>=\'\"+startmonth+\"\'\")} -- ${if(len(endmonth)==0,\"\", \" AND date_format(ld.date,\'%Y-%m\')<=\'\"+endmonth+\"\'\")} -- ${if(len(oranizationid)==0,\"\",\" and ld.sales_organization_id=\'\"+oranizationid+\"\'\")} AND ld.code not LIKE \'%-%\' AND ldd.deleted_at IS NULL AND ld.sales_organization_id is not NULL GROUP BY months,organization ) AS t ON mm.mon=t.months AND t.organization=mm.name ORDER BY mon ASC 这是完整地sql,可以不写存储过程实现的吧,感觉
    2018-12-28 10:40 
  • axing axing 回复 cipay(提问者) 不行的,你可以试试直接执行这一句都不行drop TEMPORARY table if exists MONTH_TABLE
    2018-12-28 10:48 
  • cipay cipay(提问者) 回复 axing SELECT mm.mon,mm.name,IFNULL(t.counts,\'0\') AS counts FROM (SELECT mt.MONTH_NUM AS mon, tmp.name AS name FROM (SELECT DISTINCT DATE_FORMAT(ld.date,\'%Y-%m\') AS MONTH_NUM FROM lab_dips AS ld) mt,(SELECT DISTINCT ld.sales_organization_id AS organizationid, so.name AS name FROM lab_dips AS ld LEFT JOIN sales_organization AS so ON ld.sales_organization_id=so.id WHERE ld.sales_organization_id is not NULL GROUP BY organizationid) tmp) AS mm LEFT JOIN ( SELECT DATE_FORMAT(ld.date,\'%Y-%m\') AS months, so.name AS organization, COUNT(ldd.id) AS counts FROM lab_dips AS ld LEFT JOIN lab_dip_details AS ldd ON ldd.lab_dip_id = ld.id LEFT JOIN sales_organization AS so ON ld.sales_organization_id=so.id WHERE ld.deleted_at IS NULL AND ld.code not LIKE \'%-%\' AND ldd.deleted_at IS NULL AND ld.sales_organization_id is not NULL GROUP BY months,organization ) AS t ON mm.mon=t.months AND t.organization=mm.name ORDER BY mon ASC 改成这样一个查询,可以了,但是参数有点问题
    2018-12-28 10:57 
最佳回答
0
flyingsnakeLv6资深互助
发布于2018-12-28 13:00

数据集中,是不能使用多语句的。

如果需要使用多语句,只能写存储过程来实现了

  • 3关注人数
  • 379浏览人数
  • 最后回答于:2018-12-28 13:00
    请选择关闭问题的原因
    确定 取消
    返回顶部