Where 子句停止工作

Where clause stopped working

我有这段代码(没有 WHERE,但可以正常工作)如何让它与 WHERE 子句一起工作?

我只需要它只列出当前行和最多提前 2 年的行。

$SQL = "SELECT ";
$SQL .= "SUM(Bookings.Spots) as SUMSPOT, Trips.ID, Bookings.FK_ID, Trips.MaxSpots, ";   
$SQL .= "Trips.Tripnr, Trips.StartDate, Trips.EndDate, Trips.StartLocation, ";
$SQL .= "Trips.DestinationDK, Trips.PricePerSpot "; 
$SQL .= "FROM Trips WHERE Trips.EndDate >= NOW() AND Trips.EndDate < DATE_ADD(NOW(), INTERVAL 2 YEAR) ";
$SQL .= "LEFT JOIN Bookings on Bookings.FK_ID = Trips.ID ";
$SQL .= "GROUP BY Trips.ID, Bookings.FK_ID ORDER BY Trips.StartDate ASC ";      

您需要在 LEFT JOIN 标签之后和 GROUP 标签之前添加 WHERE 子句。

您可以查看文档 here 以获取有关可以将哪个关键字放在哪里的更多答案。