Как использовать if elseif с «промежуточным» в предложении where все вместе. Пожалуйста, предоставьте подходящий пример - PullRequest
0 голосов
/ 04 апреля 2020
 1 select resort.resortid,resort.resortname,review.comments from
 2 resort inner join review on resort.resortid=review.resortid
 3 case
 4 if starrating between in 5.0 and 4.5 then
 5     {print "Excellent Resort"}
 6 
 7 else if starrating between in 4.4 and 4.0 then
 8     {print "Very Good Resort"}
 9     
10 else
11     {print "Good Resort"}
12     
13 end if

1 Ответ

0 голосов
/ 04 апреля 2020

Для примера запроса в вашем сообщении (и с использованием Oracle 11gR2) вы можете добавить starrating в качестве дополнительного столбца, используя инструкцию case. Это то, что вы хотели?

select 
    resort.resortid,
    resort.resortname,
    review.comments ,
    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 rating
from resort 
    inner join review 
    on resort.resortid=review.resortid
;


Чтобы включить значения полей (4,5, 4,0 и c.), Измените ваш SQL как:


select 
    resort.resortid,
    resort.resortname,
    review.comments ,
    case when starrating >= 4.5 and starrating < 5.0 then 'Excellent Resort'
         when starrating >= 4.0 and starrating < 4.4 then 'Very Good Resort'
         else 'Good Resort'
    end as rating
from resort 
    inner join review 
    on resort.resortid=review.resortid
;


SQL скрипка здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...