如何计算PostgreSQL中的百分比(%)

时间:2020-06-30 06:26:53

标签: postgresql postgresql-9.1 postgresql-9.4

我无法计算PostgreSQL中的% 在我的代码下方

let url = URL(string: "https://mywebsite.co.uk/loginarea.php?link=\(answer)")!

答案得到0和100而不是60%

2 个答案:

答案 0 :(得分:1)

投射为numeric的值

SELECT ROUND(( 3::NUMERIC/5::NUMERIC ) * 100);

答案 1 :(得分:0)

如果需要浮点结果,则应在计算中至少使用一个浮点数,这样整个表达式都将升为浮点数:

error[E0502]: cannot borrow `*self` as immutable because it is also borrowed as mutable
  --> src/main.rs:27:30
   |
23 |         let account = self.accounts.get_mut(id).unwrap();
   |                       ------------- mutable borrow occurs here
...
27 |         account.set(balance, self);
   |                 ---          ^^^^ immutable borrow occurs here
   |                 |
   |                 mutable borrow later used by call