开发者

Get over points

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 开发者_StackOverflow中文版


Divide the points you've got by the total, and multiply by 100:

select [got] / [total] * 100
from MyTable


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.


(12.4 / 20) x 100 will give the percentage.

So declare a percentage variable in your func, use the above and return that?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜