1

我一直在网上搜索,甚至在有关此问题的 Stackoverflow 问题中搜索,但无法收到任何相关回复。我在下面显示的 SQL 查询,

SELECT Scania.GensetType
    , Scania.EngineType
    , Scania.Engine60Hz
    , Scania.Alternator
    , Scania.PriceEur 
FROM Scania 
LEFT JOIN NordhavnGenset 
    ON Scania.GensetType=NordhavnGenset.Alternator 
WHERE (NordhavnGenset.MaxKva='46') 
    and (Generator.Alternator='ECP34-1LN/4') 
    and (insulation.Insulation='F (90ºC/45ºC)') 
    and (Klasse.Klasse='KRS\r') 
    and (airinletfilter.AirInletFilter='No') 
    and (Ip.IP='IP23');

总是返回下面的错误信息,并且我已经检查了几次,该列存在于表中!

#1054 - Unknown column 'Generator.Alternator' in 'where clause'

但是,如果我通过在第一个 Where 子句处停止来执行查询,则会显示结果,

SELECT Scania.GensetType
    , Scania.EngineType
    , Scania.Engine60Hz
    , Scania.Alternator
    , Scania.PriceEur 
FROM Scania 
LEFT JOIN NordhavnGenset 
    ON Scania.GensetType=NordhavnGenset.Alternator 
WHERE (NordhavnGenset.MaxKva='46');

新的查询

    SELECT  Scania.GensetType, Scania.EngineType, Scania.Engine60Hz, Scania.Alternator, Scania.PriceEur
FROM Scania  
LEFT JOIN NordhavnGenset
    ON Scania.GensetType=NordhavnGenset.Alternator 
LEFT JOIN Generator
    ON Scania.Alternator=Generator.Alternator
LEFT JOIN Insulation 
    ON NordhavnGenset.Insulation=Insulation.Insulation
LEFT JOIN Klasse
    ON NordhavnGenset.Class=Klasse.Class
LEFT JOIN AirInletFilter
    ON NordhavnGenset.AirInletFilter=AirInletFilter.AirInletFilter
LEFT JOIN IP
    ON NordhavnGenset.Ip=IP.IP
WHERE (NordhavnGenset.MaxKva='46') and (Generator.Alternator='ECP34-1LN/4') and (Insulation.Insulation='F (90ºC/45ºC)') and (Klasse.Klasse='KRS\r') and (AirInletFilter.AirInletFilter='No') and (IP.IP='IP23');
4

3 回答 3

7

您似乎没有加入名为 的表GeneratorWHERE除非您在其上,否则您的子句中不能包含该表JOIN

如果您添加一个JOINtoGenerator那么您可以在WHERE子句中使用它。

SELECT *
FROM Scania 
LEFT JOIN NordhavnGenset 
    ON Scania.GensetType=NordhavnGenset.Alternator 
LEFT JOIN Generator 
    ON ....
WHERE (Generator.Alternator='ECP34-1LN/4') ...

您的WHERE子句中还有其他未JOINed打开的表,因此您还需要添加这些表。

于 2012-06-18T15:35:54.067 回答
0

错误的原因是您没有加入您在WHERE子句中使用的表。

以下总是会出错 -

and (Generator.Alternator='ECP34-1LN/4') 
and (insulation.Insulation='F (90ºC/45ºC)') 
and (Klasse.Klasse='KRS\r') 
and (airinletfilter.AirInletFilter='No') 
and (Ip.IP='IP23');

您要么需要连接表,要么表的别名应该是“。”之前的名称。

于 2012-06-18T15:36:14.797 回答
0

您没有将Generator表包括在联接中。添加它,或者您可能的意思是NordhavnGenset.Alternator代替Generator.Alternator

于 2012-06-18T15:36:30.307 回答