使用别名MYSQL在CLAUSE上出现未知列错误

时间:2018-03-27 02:36:08

标签: mysql sql vb.net

我有这套SQL命令

SELECT CONCAT (
        REPEAT('    ', (COUNT(parent.itemName) - 1)),
        node.itemName
        ) AS 'NAME_',
    node.itemNo AS 'ITEM_CODE',
    node.assemblyNo AS 'ASSEMBLY_NO.',
    ref_item_type.itemTypeName AS 'TYPE_',
    node.description AS 'DESCRIPTION_',
    node.serialNo AS 'SERIAL_NO',
    node.hardwareNo AS 'HARDWARE_NO',
    node.modelNo AS 'MODEL_NO',
    node.version AS 'VERSION_',
    ref_item_uom.uomName AS 'UNIT_',
    ref_item_cat.catName AS 'CATEGORY_',
    ref_item_product_type.prodTypeName AS 'PRODUCT TYPE',
    man_network.networkName AS 'NETWORK_',
    ref_item_package.packageName AS 'PACKAGE_',
    node.reorderPoint AS 'REORDER_POINT',
    node.cost AS 'COST_',
    node.price AS 'PRICE_',
    node.surcharge AS 'SURECHARGE_',
    node.validity AS 'VALIDITY_',
    node.validityUnit AS 'VALIDITY_UNIT',
    node.isSpecialItem AS 'SPECIAL_',
    node.isActive AS 'IS_ACTIVE_',
    node.itemIndex AS 'ITEM_INDEX'
FROM man_item AS node,
    man_item AS parent
LEFT JOIN ref_item_type ON ref_item_type.itemTypeNo = node.itemType
LEFT JOIN ref_item_uom ON ref_item_uom.uomNo = node.uomNo
LEFT JOIN ref_item_cat ON ref_item_cat.catNo = node.itemCat
LEFT JOIN ref_item_product_type ON ref_item_product_type.prodTypeNo = node.prodTypeNo
LEFT JOIN man_network ON man_network.networkNo = node.networkNo
LEFT JOIN ref_item_package ON ref_item_package.packageNo = node.packageNo
WHERE node.lft BETWEEN parent.lft
        AND parent.rgt
    AND node.isVisible = 'Y'

我收到了一些错误

  

1054 - 'on clause'

中的未知列'node.itemType'

我错过了什么吗?

PS:我忘了在桌子上提到我的田地 这是btw

itemIndex   
itemNo
subItem 
assemblyNo
refNo  
prodTypeNo 
networkNo
packageNo
itemName
itemType
itemSubTypeNo
itemCat
uomNo
serialNo
hardwareNo
modelNo
version
cost
price
surcharge
validity
validityUnit
logoLocation
fileHash
lft
rgt
isSpecialItem
isActive

我不赞成不提前发布表结构,使得更加混乱和模糊

2 个答案:

答案 0 :(得分:0)

下面的子句看起来很奇怪

 FROM man_item AS node, man_item AS parent 

以下链接有类似问题的解决方案 #1054 unknown column in on clause error

答案 1 :(得分:0)

您可以尝试将此部分代码更改为正确的联接:

FROM man_item AS node, man_item AS parent LEFT JOIN ref_item_type ON ref_item_type.itemTypeNo = node.itemType 引擎可能不知道如何阅读","分隔表列表然后左连接并抛出随机错误。

FROM man_item AS node LEFT OUTER JOIN man_item AS parent ON node.lft BETWEEN parent.lft AND parent.rgt AND node.isVisible = 'Y' LEFT JOIN ref_item_type ON ref_item_type.itemTypeNo = node.itemType