Hello,
I am writing a function to get overall score in SQL
What I have is;
out of 20 points I got 12.4 points
so if I transform that, to take percentage over 100% how would I do it?
Thanx, Adnan
Hello,
I am writing a function to get overall score in SQL
What I have is;
out of 20 points I got 12.4 points
so if I transform that, to take percentage over 100% how would I do it?
Thanx, Adnan
Divide the points you've got by the total, and multiply by 100:
select [got] / [total] * 100
from MyTable
(12.4 / 20) x 100 will give the percentage.
So declare a percentage variable in your func, use the above and return that?
Presuming you mean fuction as in stored procedure, it would look like this in oracle
create or replace function pct
(p_score in number
, p_total in number)
return number
deterministic
is
begin
return p_score * (100/p_total);
end;
/
Different flavours of database have different specifications for writing stored procedures.