2015-12-15 74 views
1

我收到此錯誤消息,有人可以建議解決方案嗎?派生表中沒有指定列號的列名稱

我已經看過了這個論壇,並不能找到一個解決方案

動態SQL錯誤
SQL錯誤代碼= -104

對於沒有指定列名無效的命令列表編號1 ACCRG

SELECT DISTINCT locationgroup.name AS MainGroup, product.num AS ProductNumber, 
    product.description AS ProductDescription, uom.code AS UOM, company.name AS company, 
    sum(((SELECT SUM(productsSold.qtyfulfilled) FROM soitem productsSold WHERE soitem.id = productsSold.id AND productsSold.productid = product.id) * COALESCE(uomconversion.multiply,1))/COALESCE(uomconversion.factor,1)) AS uomqty 

FROM soitem 
    LEFT OUTER JOIN so ON (so.id = soitem.soid) 
    LEFT OUTER JOIN product ON (soitem.productid = product.id) 
    LEFT OUTER JOIN uom ON (product.uomid = uom.id) 
    LEFT OUTER JOIN locationgroup ON (so.locationgroupid = locationgroup.id) 
    LEFT OUTER JOIN qbclass ON (qbclass.id = soitem.qbclassid) 
    LEFT OUTER JOIN customer ON (customer.id = so.customerid) 
    LEFT JOIN (SELECT max(accountgrouprelation.id) AS relationID, accountgrouprelation.accountid 
         FROM accountgrouprelation 
      LEFT JOIN accountGroup ON accountGroupRelation.groupId = accountGroup.id 
      WHERE UPPER(COALESCE (accountgroup.name, '%')) LIKE UPPER('%') 
         GROUP BY 2) accrg ON customer.accountid = accrg.accountid 
    LEFT JOIN accountgrouprelation ON accrg.relationid = accountgrouprelation.id 
    LEFT OUTER JOIN accountgroup ON (accountgroup.id = accountgrouprelation.groupid) 
    LEFT OUTER JOIN uomconversion ON ((product.uomid = uomconversion.touomid) AND (soitem.uomid = uomconversion.fromuomid)) 
    JOIN company ON company.id = 1 

WHERE soitem.qtyfulfilled > 0 
    AND soitem.typeid in (10,12,80) 
    AND locationgroup.id IN (1,2,3,4) 
    AND qbclass.id LIKE '%' 
    AND UPPER(so.salesman) LIKE UPPER('%') 
    AND UPPER(COALESCE (accountgroup.name, '%')) LIKE UPPER('%') 
    AND soitem.datelastfulfillment BETWEEN '2015-11-30 23:59:59.0' AND '2015-12-31 23:59:59.0' 
GROUP BY maingroup, productnumber, productdescription, uom, company 
ORDER BY 1,product.num ASCENDING 

回答

1

不管你信不信,我認爲錯誤是從你的ORDER BY聲明來:

ORDER BY 1,product.num ASCENDING 

我不相信這是合法的ORDER BY MySQL中的常數。告訴錯誤,看起來MySQL正試圖在ACCRG派生表中找到名爲1的列。沒有這樣的列存在,因此你得到這個錯誤。相反,爲什麼不只是ORDER BY的產品編號?:

ORDER BY product.num ASCENDING 
+0

謝謝蒂姆我試試看,讓你知道如果這就是問題 – furgs09

相關問題