嘿,你能用我简单的SQL查询来帮助我吗?
表格
饭店
id | name | country | rating
1 Bali bg 4.5
2 Beach uk 4.0
3 Blue sk 3.7
游
id | id_hotel | price
1 2 250
2 2 270
3 1 250
4 1 300
5 3 250
我想要这样的东西
SELECT t.* FROM tour t LEFT JOIN hotel h ON t.id_hotel = h.id
WHERE h.country = uk GROUP BY h.id ORDER BY t.price
因此,我希望每个酒店只有一行,最低旅游价格。 最好使用Doctrine 2 queryBuilder。
感谢您的帮助。
答案 0 :(得分:0)
嘿可能我有解决方案
SELECT MIN(tour.id), hotel.* FROM `tour` INNER JOIN (
SELECT MIN(t.final_price) as final_price, t.id_hotel FROM tour t GROUP
BY t.id_hotel) ht
ON tour.id_hotel = ht.id_hotel AND tour.final_price =
ht.final_price
LEFT JOIN hotel ON hotel.id = tour.id_hotel GROUP BY tour.id_hotel
答案 1 :(得分:-1)
使用group by with order by来完成您的结果,请尝试以下查询
select hotel.name,Tour.id,Tour.price,Hotel.rating from Hotel inner join Tour on Tour.id_hotel = Hotel.id group where hotel.country = 'uk' group by Tour.id_hotel order by Tour.price asc
如果有帮助请告诉我
[编辑]此查询应与您合作