728x90

조건

 

피보나치 수열

1 1 2 3 5 8 13 ...

 

이렇게 

1분 1분 2분 3분 

지날 때마다

-2%로 이자액이 원금에서 차감되게 식 만들기 

 

 

 

 

검색통해서 피보나치 구하는 식은 썼는데 

 

시간 흐를 때마다 추가되게끔은 못함..

drop database testDB;
create database testDB;

use testDB;
create table testDB(
id INT(11)  NOT NULL AUTO_INCREMENT,                
  name VARCHAR(45) ,                        
 deposit_date DATETIME,                      
deposit_amount INT,                                   
interest_amount INT,
 CONSTRAINT testTable_PK PRIMARY KEY(id)                     
);

set @setTime = (select subtime(now(),'00:02:00'));

insert into testdb (name,deposit_date,deposit_amount,interest_amount) values ('이소윤',@setTime,10000000,0);

drop function if exists fibo_number;
DELIMITER //
CREATE FUNCTION fibo_number(n INT) RETURNS INT
DETERMINISTIC
BEGIN
	
    DECLARE f_0 INT default 0;
    DECLARE f_1 INT default 1;
    DECLARE out_fib INT;
    DECLARE i INT;
    DECLARE f_2 INT;

    SET f_0 = 0;
    SET f_1 = 1;
    SET i = 1;

    
    WHILE (i<=n) DO
   
        SET f_2 = f_0 + f_1;
        SET f_0 = f_1;
        SET f_1 = f_2;              
       SET i = i + 1;  
       SET out_fib = f_0;          
	
    END WHILE;
    	  RETURN out_fib;


END //

set @n =  (select fibo_number(6))//
select @n//

drop procedure if exists pro//
create procedure pro()
begin

while (select id from testdb order by id desc limit 1) < 10 do
INSERT INTO testdb (name,deposit_date,deposit_amount,interest_amount) 
select 
(select  MIN(name) from testdb),
date_add((select MAX(deposit_date) from testdb),INTERVAL @n minute),
((select MIN(deposit_amount) from testdb ) - (select MAX(interest_amount) from testdb)),
(select deposit_amount from testdb where id =1)* 0.02;
end while;
end //
delimiter ;

call pro();

select * from testdb;

 

https://shoark7.github.io/programming/algorithm/%ED%94%BC%EB%B3%B4%EB%82%98%EC%B9%98-%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98%EC%9D%84-%ED%95%B4%EA%B2%B0%ED%95%98%EB%8A%94-5%EA%B0%80%EC%A7%80-%EB%B0%A9%EB%B2%95.html

 

피보나치 수열 알고리즘을 해결하는 5가지 방법

Let me introduce 5 different ways to solve fibonacci algorithm

shoark7.github.io

https://hongjw1938.tistory.com/47

 

알고리즘 - Dynamic Programming(동적 계획법)

1. 개요 DP, 즉 다이나믹 프로그래밍(또는 동적 계획법)은 기본적인 아이디어로 하나의 큰 문제를 여러 개의 작은 문제로 나누어서 그 결과를 저장하여 다시 큰 문제를 해결할 때 사용하는 것으

hongjw1938.tistory.com

https://stackoverflow.com/questions/69821788/create-and-call-mysql-function-to-find-fibonacci-numbers-till-n-numbers

 

Create and call MYSQL Function to find Fibonacci numbers till n numbers

My approach DELIMITER $$ CREATE FUNCTION fibonacci(num INT) RETURNS INT DETERMINISTIC BEGIN DECLARE fib1 INT DEFAULT 0; DECLARE fib2 INT DEFAULT 1; DECLARE fib3 INT DEFAULT 0; DECLA...

stackoverflow.com

 

728x90

+ Recent posts