Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 821
emma_soraya Avatar asked Nov 16 '25 11:11

emma_soraya


1 Answers

If scholarship might be NULL replace it with nvl(scholarship,0) or coalesce(scholarship,0)

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) ...
like image 117
David דודו Markovitz Avatar answered Nov 19 '25 09:11

David דודו Markovitz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!