我正在尝试在 mysql 中实现一个基于计算返回天数的过程。购买日期(added_date)传入,然后计算完成。应该相对简单,但我似乎无法让它发挥作用。我不确定这是否适合“选择语句”,如果这非常简单,我深表歉意,但这是我第一次运行程序。
如果有人可以告诉我应该怎么做,将不胜感激。
谢谢!
我有一个名为“计算”(表 3)的表,其中包含字段“elap_yend”(int),该字段当前为空,直到调用存储过程。
表格1:
cid parent_cat category_name category_life
22 0 Office Equipment-M' 1080
23 0 Office Equipment-O' 1800
24 0 F & F' 3600
25 0 Staff assets', 1800
27 0 Motor vehicle', 2880
28 0 Air conditioner' 5400
29 0 Land & Building', 2160
30 0 Temporary Partition 365
31 0 Electrical Fittings 3600
32 0 Generator' 5400
33 0 Software' 1800
34 0 Computer-N' 2160
35 24 chair' 3600
表 2:
pid cid product_name product_price added_date cgst sgst igst total depre
60 22 RHFL\test\001 20000 2018-11-02 1800 1800 0 23600 o
61 27 RHFL\test\002 13500 2018-11-02 2345 2345 0 15930 12
62 29 RHFL\test\003 65000 2018-11-02 2345 2345 0 76700 12
63 31 RHFL\test\004 10000 2018-11-02 2345 2345 0 1180 12
64 24 RHFL\test\005 10000 2018-11-02 2345 2345 0 11800 1
65 24 RHFL\test\006 13500 2018-11-02 2345 2345 0 15930 12
66 34 RHFL\test\007 13500 2018-11-02 2345 2345 0 15930 12
67 22 RHFL\test\008 65004 2018-11-02 2345 2345 0 76704 12
68 25 RHFL\test\009 10000 0000-00-00 2345 2345 0 11800 12
69 22 RHFL\test\010 65000 0000-00-00 2345 2345 0 76700 10
70
表3:存储过程的输出应体现在下表中:
end_date elap_yend rem_days depre_cur cur_wdv depre_next next_wdv acc_depre
2018-11-02 0 0 0 0 0 0
输出计算:
以上是零的样本输出。这不是确切的输出,但每当我调用存储过程时,它应该在下面进行这些计算。
DELIMITER $$
CREATE PROCEDURE calculationTemp(
in till_yend date,
)
BEGIN
DECLARE till_yend date;
SELECT datediff(now(),added_date) INTO till_yend
FROM products
IF till_yend > 0 THEN
SET till_yend = select datediff(now(),added_date) from products;
ELSEIF till_yend < 0 THEN
SET till_yend = 0;
END IF;
insert into calculationTemp
END$$
计算工作:
Elapsed year end : elapsed_yend = added_date(from products table (No:2)) 直到每年 31/March/xxxx。
这两个日期之间的天数
剩余天数 = 类别寿命 - (添加日期(从产品(编号:1)到日期)之间的日期差异)
category_life(来自类别表(编号:1))例如:移动设备的寿命为 1080 天。
本年度折旧:depreciation_cur = (depre/category_life)*elapsed_yend
本年度 减记值:
current_wdv = depre - depreciation_cur
明年折旧:depreciation_next = (depre / category_life) * D D = 每年 01/4/xxxx 到 end_date 之间的天数差异(来自计算表)
下一年 减记值:
next_wdv = current_wdv - depreciation_next
累计折旧:
累积折旧 = 折旧 - 曲线 + 折旧 - 下一个