Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

再来一个SQL解析异常 #2765

Closed
JackieXiangxy opened this issue Jul 5, 2024 · 4 comments
Closed

再来一个SQL解析异常 #2765

JackieXiangxy opened this issue Jul 5, 2024 · 4 comments

Comments

@JackieXiangxy
Copy link

版本号:

1.7.6

问题描述:

当sql中存在两个查询用union进行结果拼接时,sql解析出来的效果不一致,前面一个sql的where条件后没有自动生成1=1,而第二个sql的where条件后出现了1=1。两个解析结果不一致
image

错误日志&截图:

原始sql
image

解析后的sql
image

重现步骤:

友情提示(为了提高issue处理效率):

  • 积木报表是一款免费报表产品,功能免费源码不开放;
  • 未按格式要求发帖,会被直接删掉;
  • 请针对问题提供[报表设计配置或SQL脚本]或在官网制作报表示例并提供ID;
  • 针对不好重现的问题,请录制操作视频或详细的重现步骤;
@JackieXiangxy
Copy link
Author

JackieXiangxy commented Jul 5, 2024

我将sql贴出来。这个SQL可以验证我提出来的两个issue

select a.creatorName,a.fsOutpatientName,a.createDate,a.code,a.patientName,a.docDeptName,
a.docName,GROUP_CONCAT(a.drugName) drugName,sum(a.preferential) preferential,sum(a.realAmount) realAmount,sum(a.nowPay) nowPay,
sum(a.bankPay) bankPay,
sum(a.renderAccount) renderAccount,sum(a.insuranceRenderAccount) insuranceRenderAccount,a.chargeTypeName,a.cardNumber,a.regCode,
a.prCreateDate,a.prCode from (
SELECT bpi.fsOutpatientName,pp.name creatorName,boc.createDate,bi.code,bi.name patientName,
       pd.name docDeptName,pp1.name docName,CONCAT(bpi.name,' X ',bpi.num,bpi.unitName) drugName,
       boci.preferential,boci.realAmount,boci.nowPay,boci.bankPay,boci.renderAccount,boci.insuranceRenderAccount,
       boc.chargeTypeName,ba1.cardNumber,brf.code regCode,bp.createDate prCreateDate,bp.code prCode
  FROM b_outpatient_charge_item boci
  LEFT JOIN b_outpatient_charge boc ON boc.id=boci.charge_id
  LEFT JOIN b_prescription_item bpi ON bpi.id=boci.prescription_item_id
  LEFT JOIN b_prescription bp ON bp.id=bpi.prescription_id
  LEFT JOIN pl_person pp ON pp.id=boc.creator_id
  LEFT JOIN b_invoice bi ON bi.id=boci.invoice_id
  LEFT JOIN pl_department pd ON pd.id=bp.doctor_dept_id
  LEFT JOIN pl_person pp1 ON pp1.id=bp.doctor_id
  LEFT JOIN b_reg_from brf ON brf.id=boc.form_id
  LEFT JOIN b_account ba1 ON ba1.id=brf.account_id
  WHERE 
				<#if isNotEmpty(startTime)> 
				AND boc.createDate >= '${startTime}'
			</#if>
			<#if isNotEmpty(endTime)> 
				AND boc.createDate  <= '${endTime}'
			</#if>
			<#if isNotEmpty(doctorId)> 
				and and pp1.id='${doctorId}'
			</#if>
  GROUP BY boci.id
) a group by a.prCode,a.fsOutpatientName
union
select a.creatorName,a.fsOutpatientName,a.createDate,a.code,a.patientName,a.docDeptName,
a.docName,GROUP_CONCAT(a.drugName) drugName,sum(a.preferential) preferential,sum(a.realAmount) realAmount,sum(a.nowPay) nowPay,
sum(a.bankPay) bankPay,sum(a.renderAccount) renderAccount,sum(a.insuranceRenderAccount) insuranceRenderAccount,a.chargeTypeName,
a.cardNumber,a.regCode,a.prCreateDate,a.prCode from (
SELECT bpi.fsOutpatientName,pp.name creatorName,boc.createDate,bi.code,bi.name patientName,
       pd.name docDeptName,pp1.name docName,CONCAT(bpi.name,' X ',bpi.num,bpi.unitName) drugName,
       boci.preferential,boci.realAmount,boci.nowPay,boci.bankPay,boci.renderAccount,boci.insuranceRenderAccount,
       boc.chargeTypeName,ba1.cardNumber,brf.code regCode,bp.createDate prCreateDate,bp.code prCode
  FROM b_outpatient_charge_item boci
  LEFT JOIN b_outpatient_charge boc ON boc.id=boci.charge_id
  LEFT JOIN b_prescription_item bpi ON bpi.id=boci.prescription_item_id
  LEFT JOIN b_prescription bp ON bp.id=bpi.prescription_id
  LEFT JOIN pl_person pp ON pp.id=boc.creator_id
  LEFT JOIN b_invoice bi ON bi.id=boci.invoice_id
  LEFT JOIN pl_department pd ON pd.id=bp.doctor_dept_id
  LEFT JOIN pl_person pp1 ON pp1.id=bp.doctor_id
  LEFT JOIN b_reg_from brf ON brf.id=boc.form_id
  LEFT JOIN b_account ba1 ON ba1.id=brf.account_id
  WHERE 
			<#if isNotEmpty(startTime)> 
				AND boc.createDate >= '${startTime}'
			</#if>
			<#if isNotEmpty(endTime)> 
				AND boc.createDate  <= '${endTime}'
			</#if>
			<#if isNotEmpty(doctorId)> 
				and oci.bill_person_id='${doctorId}'
			</#if>
			<#if isNotEmpty(doctorId)> 
				and and pp1.id='${doctorId}'
			</#if>
) a group by a.prCode,a.fsOutpatientName




@zhangdaiscott
Copy link
Member

你用的是那种模式?

@JackieXiangxy
Copy link
Author

你用的是那种模式?

把sql写好后点击解析按钮 就可以触发这个bug。我这经触发了很多次了

image

@1298191366
Copy link

已修复,待新版本发布。后续需要你自行填写1=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants