直到最近,以下SQL语句在使用MSSQL数据库时没有任何问题:
SELECT DISTINCT Flights.MODEL_ID,
Pilots.NAME,
Models.DESCRIPTION,
Flights.KURSLAENGE * 4828 * Flights.DREIECKE + Flights.SPEED AS POINTS,
Flights.SPEED,
Flights.DREIECKE * Flights.KURSLAENGE * 0.0048284 AS DISTANZ,
Flights.FLIGHT_ID,
Pilots.PILOT_ID,
Flights.STARTZEIT,
Flights.DREIECKE,
Flights.CATEGORY_ID,
Pilots.VORNAME,
Flights.KURSLAENGE,
Flights.PLACE_ID
FROM Flights
INNER JOIN Models
ON Flights.MODEL_ID = Models.MODEL_ID
INNER JOIN Pilots
ON Models.PILOT_ID = Pilots.PILOT_ID
WHERE ( Flights.STARTZEIT <= @DateMax )
GROUP BY Pilots.NAME,
Models.DESCRIPTION,
Flights.KURSLAENGE * 4828 * Flights.DREIECKE + Flights.SPEED,
Flights.MODEL_ID,
Flights.SPEED,
Flights.DREIECKE * Flights.KURSLAENGE * 0.0048284,
Flights.FLIGHT_ID,
Pilots.PILOT_ID,
Flights.STARTZEIT,
Flights.DREIECKE,
Flights.CATEGORY_ID,
Pilots.VORNAME,
Flights.KURSLAENGE,
Flights.PLACE_ID
HAVING ( Flights.CATEGORY_ID = @CatId )
AND ( Flights.STARTZEIT >= @DateMin )
ORDER BY POINTS DESC
现在我收到了错误:
如果SELECT DISTINCT为,则ORDER BY项必须出现在选择列表中 指定的
将'ORDER BY POINTS DESC'替换为例如'ORDER BY Flights.SPEED DESC'也可以。
上述陈述不再起作用的原因是什么?