这是有效的 SQL 吗?as well的用法对GROUP BY
吗?
另外,如何按 TOTAL 对结果进行排序?
谢谢
SELECT packages.id AS PPIIDD,
Q_ALLOTMENTS.total AS TOTAL,
roomname,
hotelrooms.room_id AS RID,
packages.description AS PDESC,
hotelname,
regionname,
places.name AS PLACENAME,
destinationname,
hotels.property_desc,
hotels.hotel_id AS HID,
room_rates.high AS ROOM_HIGH,
packages.low AS PLOW,
hotels.startype,
address1,
address2,
town,
postcode,
hotelrooms.room_id AS RID,
packages.type AS PTYPE
FROM packages
INNER JOIN hotels
ON hotels.hotel_id = packages.hotel_id
AND hotels.status = 'active'
INNER JOIN allotments_new
ON allotments_new.package_id = packages.id
AND allotments_new.day_date >= '2013-04-17'
AND allotments_new.day_date < '2013-04-18'
AND allotments_new.day_rate > 0
AND allotments_new.status != 'n'
AND allotments_new.minimum_number_of_nights <= 1
INNER JOIN hotelrooms
ON hotelrooms.room_id = packages.room_id
AND hotelrooms.status = 'active'
INNER JOIN room_rates
ON room_rates.room_id = hotelrooms.room_id
INNER JOIN destinations
ON destinations.destination_id = hotels.destination_id
INNER JOIN regions
ON regions.region_id = hotels.region_id
LEFT OUTER JOIN places
ON places.id = hotels.places_id
INNER JOIN (SELECT Sum(day_rate) AS TOTAL,
allotments_new.status,
allotments_new.number_of_rooms,
day_rate,
day_date,
package_id
FROM allotments_new
WHERE allotments_new.day_date >= '2013-04-17'
AND allotments_new.day_date < '2013-04-18'
AND allotments_new.day_rate > 0
AND allotments_new.status != 'n'
AND allotments_new.minimum_number_of_nights <= 1
GROUP BY allotments_new.status,
allotments_new.number_of_rooms,
day_rate,
day_date,
package_id) AS Q_ALLOTMENTS
ON Q_ALLOTMENTS.package_id = packages.id
WHERE hotels.hotel_id = '1875'
AND packages.status = 'active'
AND hotels.status = 'active'
AND hotelrooms.status = 'active'
AND maximum_number_of_adults_and_children >= '1'
AND 1 = '1'
AND 1 = '1'
AND 1 = '1'
AND 1 = '1'
AND 1 = '1'
AND 1 = 1
AND 1 = 1
GROUP BY ppiidd
ORDER BY startype DESC