Advertisement
inkarnasion

11.Calculating Interest

Oct 14th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.57 KB | None | 0 0
  1. CREATE PROCEDURE usp_calculate_future_value_for_account(
  2.     acc_id INT(11),
  3.     rate DECIMAL(19,4))
  4. BEGIN
  5.     DECLARE value DECIMAL(19,4);
  6.     DECLARE balance DECIMAL(19,4);
  7.     SET balance := (SELECT a.balance FROM accounts AS a WHERE a.id = acc_id);
  8.     SET value := balance * (pow(1 + rate, 5));
  9.     SELECT
  10.         a.id AS 'account_id',
  11.         ah.first_name,
  12.         ah.last_name,
  13.         balance AS 'current_balance',
  14.         value AS 'balance_in_5_years'
  15.     FROM accounts AS a
  16.         JOIN account_holders AS ah
  17.         ON a.account_holder_id = ah.id
  18.         AND
  19.         a.id = acc_id;
  20. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement