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;
피보나치 수열 알고리즘을 해결하는 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
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
'데이터베이스 > mySQL' 카테고리의 다른 글
The difference between "mysql" and "mysql -u root -p" (0) | 2023.02.08 |
---|---|
mysql EVENT스케줄러 (자동생성) (0) | 2022.05.18 |
mysql null값 뜨는 이유, where조건문...empty set (0) | 2022.05.13 |
mysql 한시간마다 이자액으로 원금 줄어드는 계산식 MAX MIN 사용 (0) | 2022.05.13 |
MAX MIN order by limit 차이 뭘 쓸지 (0) | 2022.05.13 |