尝试这个:
SELECT * FROM hoteldata where price = (SELECT min(price) FROM hoteldata)
SELECT hd.*
FROM (
SELECT hotelname , MIN(price) as minprice
FROM hoteldata
GROUP BY hotelname
) minprices
JOIN hoteldata hd
ON hd.hotelname = minprices.hotelname
AND hd.price = minprices.minprice
Note: If two rooms in one hotel have the lowest price, they will be listet both.
For performance you should define an index on ( hotelname , price )
SELECT *
FROM (hoteldata) order by price asc limit 1;
This will work for getting minimum price room from different hotel.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.