我有这个错误。我对SQL还不熟悉,不知道我的语法出了什么问题。我将INTERSECT语句更改为内部连接,发现SQL不接受这种语法。不过,我还是有一个错误。
错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use n
ear 'a
INNER JOIN
(Select h.propertyId as id
From House h, has_weather hw, weather_ye' at line 8
该查询假设查找用户id和属性的电子邮件,这些用户的评级为5,AvgTemp超过55。
Select has_property.userId
From has_property
Where has_property.propertyId IN
(
(Select hRR.propertyId as id
From hasRatings_Rate hRR
Where hRR.ratingId = 5
) a
INNER JOIN
(Select h.propertyId as id
From House h, has_weather hw, weather_year wy
Where hw.weatherId = wy.weatherId AND hw.homeAddId = h.homeAddId AND wy.AvgTemp > 55
)b
ON (a.id = b.id)
);
最佳答案
试试这个:
Select has_property.userId
From has_property hp
JOIN hasRatings_Rate hRR ON hp.propertyId = hRR.propertyId
JOIN House h ON h.id = hRR.id
JOIN has_weather hw ON hw.homeAddId = h.homeAddId
JOIN weather_year wy ON hw.weatherId = wy.weatherId
WHERE hRR.ratingId = 5
AND wy.avgTemp > 55
不需要任何子查询,只需要一系列连接。