emma_soraya emma_soraya - 1 month ago 6
SQL Question

SQL oracle add a value

Let`s say I want to select the students with scholarship and add to that value 150 and for those with no scholarship to add 100.I tried :

select name,scholarship+150 as "New scholarship" from students where bursa is not null union select name,scholarship+100 as "New scholarship" from students where bursa is null;

but only for those who had scholarship added the new value .Can you please help me

Answer
select scholarship + case when bursa is not null then 150 else 100 end ...

or

select scholarship + decode (bursa,null,100,150) ...

or

select scholarship + nvl2 (bursa,150,100) ...
Comments