【发布时间】:2016-11-21 17:44:04
【问题描述】:
我有两张桌子:
hotels
id, hotel
rooms
id , hotel, type, stay, price
在第二张桌子上,根据房间用餐(住宿)的不同,有不止一排相同房型的不同价格。
我怎样才能只叫第二张桌子上该房型最低价格的一行?
我的代码如下
select h.hotel
, r.hotel
, r.stay
, r.type
, r.price
from hotels h
LEFT
JOIN rooms r
ON r.hotel = h.hotel
where r.type = '$rtype1
GROUP
BY r.hotel
ORDER
BY r.price asc
$rtype 是访问者通过输入字段发送的值
【问题讨论】:
-
rooms.type='$rtype1是错字吗? -
欢迎来到 Stack Overflow!您可以阅读如何How to Ask 一个问题并创建一个minimal reproducible example。这让我们更容易为您提供帮助。
-
$rtype 是访问者通过输入字段发送的值
-
请注意:在 sql 查询中直接使用用户输入存在安全风险,并且允许 sql injection。有很多方法可以避免这种情况,this tutorial 中描述了一些方法。