Question

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

Was it helpful?

Solution

Presuming you mean "function" 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.

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top