客人希望根据度假村的星级来显示度假村的ID、名称和评论。
度假村的评论显示如下
如果评分在5.0到4.5之间,则显示评论为 "优秀度假村"。
如果评分在4.4到4.0之间,则显示评论为 "非常好的度假村"。
否则显示'好的度假村'。给这个结果取别名作为评论。
根据度假村ID对结果进行排序。
如果我正确阅读模型,那么
resort
桌子with ratings as
(select resort_id,
round(avg(star_rating), 1) rating
from resort
group by resort_id
)
select
r.resort_id,
r.resortname,
case when c.rating between 4.5 and 5.0 then 'Excellent'
when c.rating between 4.0 and 4.4 then 'Very good'
else 'Good'
end comment
from resort r join ratings c on r.resort_id = c.resort_id
select resortid, resortname,
case when starrating between 4.5 and 5.0 then 'Excellent Resort'
when starrating between 4.0 and 4.4 then 'Very Good Resort'
else 'Good Resort'
end as comments
from resort
order by resortid;
这样