【发布时间】:2019-12-07 03:49:40
【问题描述】:
我正在查询我的数据库中的一个零件表,我将在该表中加入库存和其他表,以便如果库存没有数量,我可以返回“不可用”来代替数量。
这是我的查询:
select partNumber, 1 as QtyRequired, IFNULL(inventory.Quantity,0) as QtyAvailable,IFNULL(Stagename,"Not Available") as Stagename,IFNULL(LocationName,"Not Available") as LocationName from parts
left join inventory on parts.partID = inventory.partid
left join locations on inventory.LocationID = locations.LocationID
left join stages on inventory.StageID= stages.StageID and stagename <> 'green'
where assembly is true and parts.partID = 7732
问题是我不想在舞台名称为绿色时返回数量。
现在我的数据库中有一行 partID 7732,它处于绿色阶段,但它确实有一个位置。我得到的结果是:
PartNumber QtyRequired QtyAvailable StageName LocationName
SENSODINE2 1 150 Not Available Warehouse5
我期待的是
PartNumber QtyRequired QtyAvailable StageName LocationName
SENSODINE2 1 0 Not Available Not Available
为了实现这一点,我想我会做这样的事情:
select partNumber, 1 as QtyRequired, IFNULL(inventory.Quantity,0) as QtyAvailable,IFNULL(Stagename,"Not Available") as Stagename,IFNULL(LocationName,"Not Available") as LocationName from parts
left join inventory on parts.partID = inventory.partid and stagename <> 'green'
left join locations on inventory.LocationID = locations.LocationID and stagename <> 'green'
left join stages on inventory.StageID= stages.StageID and stagename <> 'green'
where assembly is true and parts.partID = 7732
但是这样做给了我:
错误代码 1054:“on 子句”中的未知列“stagename”
【问题讨论】:
-
为什么
Stagename在 select 子句中是大写的,而在 on 子句中却不是?
标签: mysql