dongtangu6889 2019-03-08 01:26
浏览 55
已采纳

按照其他列中的值按计划更新每列

I have a users table and two columns are having a relationship. The value of the first column is the monthly deductions of each user.

I want the data in the first column to keep auto increasing itself in the other column on a monthly basis. Example: if user A has $5 as their monthly deduction and has $10 as their total_deduction in February, by march the total deduction should auto increase to $15.

I could use event in phpmyadmin sql I guess.

  • 写回答

1条回答 默认 最新

  • douzhuiqing1151 2019-03-08 02:27
    关注

    Absolutely, you can schedule an event for monthly deduction. Before creating an event make sure in your mysql you set event_scheduler is ON which in default is OFF.

    SET GLOBAL event_scheduler = ON;
    

    Event: you can add fixed amount or user-wise deduction from another column.

    1) For fixed amount:

    CREATE EVENT user_monthly_deduction
    ON SCHEDULE EVERY '1' MONTH
    DO
    BEGIN
      UPDATE test.users SET total_deductions = total_deductions + $5;
    END$$
    

    2) From another column:

    CREATE EVENT user_monthly_deduction
    ON SCHEDULE EVERY '1' MONTH
    DO
    BEGIN
      UPDATE test.users SET total_deductions = total_deductions + monthly_deduction;
    END$$
    

    For more details about events-configuration and create_event you can check this official document. mysql-event-configuration and create-event

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题