duaabhuv188411 2016-02-25 20:14
浏览 59
已采纳

将公式转换为SQL查询

I am building a system where it would output the total current balance to the user.

I have a three MySQL tables, first a Members table where the user data session gets the Member_ID second is Regular_Savings and the third (The Out Put Table) Current_Balance

I have the Math formula how to work out the interest (see bellow)

enter image description here

I would like Total_Balance in Current_Balance table to use the output the current balance, I was trying to use the query bellow but think I have made a few mistakes.

Query And Codeigniter Model Code

function get_bank()
    {
        $this->db->SELECT(`Principle` * (POWER((1 + (`Annual_Rate_Interest` DIV `Compound`)),(`Valid_For` * `Compound`)))) +((`monthly_deposit` * (POWER((1 + (`Annual_Rate_Interest` DIV `Compound`)),(`Valid_for` * `Compound`)) -1)) DIV(`Annual_Rate_Interest` DIV `Compound`)) as fav, $this->session->userdata("Member_ID"));
        $query = $this->db->get('Regular_Savings');
        return $query->result();
    }

Formula enter image description here

All help is very much appreciated, Thank You.

****************UPDATE********************

As suggested in a comment, I could use PHP, I the code bellow is close I think, but not right, any ideas ?

Possible PHP solution

<?php
function interest($Principle,$Compound,$Annual_Rate_Intrest,$Valid_For){
    $Accumulated=0;
    if ($Compound > 1){
            $Accumulated=interest($Principle,$Compound-1,$Annual_Rate_Intrest,$Valid_For);
            }
    $Accumulated += $Principle;
    $Accumulated = $Accumulated * pow(1 + $Annual_Rate_Intrest/(100 * $Valid_For),$Valid_For);
    return $Accumulated;
    }
?>
  • 写回答

1条回答 默认 最新

  • dpvhv66448 2016-02-25 22:10
    关注

    Using the shorthands outlined in your table, the calculation should be

    // p : principal
    // i : annual rate interest
    // c: compound
    // n : valid for
    // R : monthly deposit
    
    // calculate the terms that appear twice
    $x = $i / $c;
    $y = pow ( (1 + $x), ($n * $c) );
    
    $vf = $p * $y + ( ($R * $y - 1 ) / $x );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu服务器配置dns域名后无法访问其他域名
  • ¥50 本人复制了一个关于股票指标的代码,但是运行失败,有没有人帮我解决一下
  • ¥50 用matlab和numeca做透平机械流体力学和热力学模拟 价格可议
  • ¥15 Unity3D WebView
  • ¥20 论文AlphaTensor复现(有偿)
  • ¥15 (有偿)在ANSYS中 .anf文件
  • ¥45 关于#芯片#的问题:组合逻辑电路设计
  • ¥15 基与机器学习和时间序列分析预测养老服务需求趋势
  • ¥100 求连续两帧图像在水平和垂直上偏移
  • ¥15 Verilog hdl密码锁设计