我一直在网上搜索,甚至在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');
答案 0 :(得分:7)
您似乎没有加入名为Generator
的桌子。除非您WHERE
,否则您无法在JOIN
子句中使用该表。
如果您向JOIN
添加Generator
,则可以在WHERE
子句中使用它。
SELECT *
FROM Scania
LEFT JOIN NordhavnGenset
ON Scania.GensetType=NordhavnGenset.Alternator
LEFT JOIN Generator
ON ....
WHERE (Generator.Alternator='ECP34-1LN/4') ...
您的WHERE
子句中还有其他表格不是JOINed
,因此您还需要添加这些表格。
答案 1 :(得分: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');
您需要将表连接起来,或者表的别名应该是'。'之前的名称。
答案 2 :(得分:0)
您未在联接中包含Generator
表。可以添加它,也可以表示NordhavnGenset.Alternator
而不是Generator.Alternator