gpt4 book ai didi

mysql查询返回具有某一列的MAX值的记录

转载 作者:行者123 更新时间:2023-11-29 18:16:20 30 4
gpt4 key购买 nike

我目前拥有以此数据库架构表示的数据库。

数据库架构

enter image description here

这里我想要一个查询来获取给定目的地中具有最高评级值的住宿名称,该目的地的房间 ID 的人均价格值小于给定值。

评级表样本数据

例如:我想获取位于纽约且评值(value)最高的客房人均价格低于 50 美元的酒店名称。 Sample rating table

最佳答案

我没有测试它,但以下查询应该可以工作:

select ac.name as hotel
from accomodation ac
inner join room r
on r.accomodation_id = ac.accomodation_id
inner join rating ra
on ra.rating_id = ac.rating_id
where
ac.destination_id in (select destination_id from destination where name = 'New York')
and
r.room_id in (select room_id from room where price_per_head < 50)
order by ra.value desc
limit 1;

关于mysql查询返回具有某一列的MAX值的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46988991/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com