首页 > 解决方案 > oracle中如何对列数据进行注释?

问题描述

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

度假村显示评论如下

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

如果评分介于 4.4 到 4.0 之间,则将评论显示为“非常好的度假村”

否则显示 'Good Resort' 。将此结果的别名命名为 Comments。

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

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

标签: oraclecomments

解决方案


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

  • 计算平均评分
  • 把它和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

推荐阅读