Where子句停止工作

时间:2017-09-13 06:42:09

标签: php sql date where clause

我有这个代码(没有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 ";      

1 个答案:

答案 0 :(得分:0)

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

您可以查看文档here,了解有关在何处放置关键字的更多答案。