【问题标题】:SQL subSelect Statement issue in iReportiReport 中的 SQL subSelect 语句问题
【发布时间】:2016-05-02 18:08:38
【问题描述】:

我正在使用 iReport 编写自定义报告,但遇到了问题。

我正在尝试通过添加以下代码行来更改现有报告:

LEFT JOIN (select info from customfieldview where cftableid = 97022306 and recordid = so.id and cfname = 'SIN')

字段和表名都是正确的,但无论出于何种原因,它都说我的“WHERE”语句搞砸了。对于 iReport,它的调试器通常会说问题是实际问题下方的行,而我的 WHERE 语句之前的行恰好是我的 subSELECT 语句。

我将发布我的 SQL 和一张突出我的问题的照片。

我的 subSelect 语句格式不正确吗?

SELECT (case when $P{ckShowHistoricalProductNumber} = 1 then soitem.productnum else product.num end) AS soitemproductnum, soitem.description AS soitemdescription,
(case when soitem.uomid != product.uomid then ((postsoitem.qty*uomconversion.multiply)/uomconversion.factor) else postsoitem.qty end) AS postsoitemqty,
producttree.name AS producttreename,
(CASE WHEN soitem.uomid != product.uomid then (soitem.unitprice/uomconversion.multiply)*uomconversion.factor else soitem.unitprice end) + (soitem.adjustamount / (CASE WHEN soitem.qtytofulfill = 0
                                                        THEN 1
                                                        ELSE soitem.qtytofulfill END)) AS soitemunitprice, soitem.typeid AS soitemtypeid,
company.name AS company, uom.code AS uomcode, currency.symbol

FROM soitem
LEFT JOIN postsoitem ON soitem.id = postsoitem.soitemid
JOIN postso on postsoitem.postsoid = postso.id
JOIN product ON soitem.productid = product.id
LEFT JOIN producttotree ON product.id = producttotree.productid
LEFT JOIN producttree ON producttotree.producttreeid = producttree.id
LEFT JOIN uom ON product.uomid = uom.id
LEFT JOIN uomconversion on product.uomid = uomconversion.touomid and soitem.uomid = uomconversion.fromuomid
INNER JOIN company ON company.id = 1
LEFT JOIN currency ON currency.homeCurrency = 1
LEFT JOIN (select info from customfieldview where cftableid = 97022306 and recordid = so.id and cfname = 'SIN')

WHERE postso.postdate BETWEEN $P{dateRange1} AND $P{dateRange2}
AND soitem.typeid IN (10,11,12,21,30,31,40,50,60,70,80)
AND ((COALESCE(producttreeid,0) IN ($P!{productTree1})) OR ((COALESCE(producttreeid,0) LIKE $P{productTree2})))
AND (CASE WHEN $P!{ckShowEachProductOnce} =1 then (Select first 1 producttree.id
       FROM product AS p1
       LEFT JOIN producttotree ON p1.id = producttotree.productid
       LEFT JOIN producttree ON producttotree.producttreeid = producttree.id
       WHERE p1.id = product.id
       AND ((COALESCE(producttreeid,0) IN ($P!{productTree1})) OR ((COALESCE(producttreeid,0) LIKE $P{productTree2})))) else producttree.id end) = producttree.id

【问题讨论】:

  • 您检查查询了吗(在将参数替换为值之后)?
  • @AlexK 据我所知,整个查询工作得非常好,直到我添加了 subSelect 行。 ://
  • 这个查询(带有子选择)怎么样?
  • 为您的子查询添加别名

标签: sql jasper-reports subquery


【解决方案1】:

事实证明,问题在于我编写 subQuery 的方式。

我使用的是LEFT JOIN (select info from customfieldview where cftableid = 97022306 and recordid = so.id and cfname = 'SIN')

并说它是一个子查询,而实际上因为它在FROM 条件/参数中使用,那么它实际上是一个派生表

我不知道有什么区别!

感谢你们的意见和有用的提示!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 2010-09-25
    • 1970-01-01
    • 2011-09-12
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多