如何给oracle中的列数据添加注释?[重复]

问题描述 投票:0回答:2

客人希望根据度假村的星级来显示度假村的ID、名称和评论。

度假村的评论显示如下

如果评分在5.0到4.5之间,则显示评论为 "优秀度假村"。

如果评分在4.4到4.0之间,则显示评论为 "非常好的度假村"。

否则显示'好的度假村'。给这个结果取别名作为评论。

根据度假村ID对结果进行排序。

https://i.stack.imgur.com/vvvNz.png

oracle comments
2个回答
1
投票

如果我正确阅读模型,那么

  • 计算平均分
  • 与之相接 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

0
投票
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;

这样

© www.soinside.com 2019 - 2024. All rights reserved.