我有两个表,第一个是hotel_info
,其中包含(hotel_id
,hotel_name
,location
)和第二个表rooms
等字段,有空间信息,例如(room_id
,room_name
,hotel_id
,rate
,description
)。我想要一个查询,返回酒店的最低房价以及hotel_info
表中有关酒店的所有信息。到目前为止,我有这个查询正常工作,但它没有返回最低房价。
SELECT a.hotel_id,a.hotel_name ,a.location, b.rate FROM hotel_info a
LEFT JOIN rooms b ON b.hotel_id=a.hotel_id
GROUP BY hotel_id
如何获得每间酒店的最低房价?
答案 0 :(得分:2)
您可以使用mysql函数min(),例如
select a.hotel_id, min(b.rate)
from hotel_info a
left join rooms b on b.hotel_id = a.hotel_id
group by a.hotel_id;
答案 1 :(得分:1)
SELECT a.hotel_id, a.hotel_name, a.location, min(b.rate) as min_rate
FROM hotel_info a
LEFT JOIN rooms b ON b.hotel_id = a.hotel_id
GROUP BY a.hotel_id, a.hotel_name, a.location