Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9310411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:06:19+00:00 2026-06-19T01:06:19+00:00

I have created an event which will update the balance in table ‘try_event’ after

  • 0

I have created an event which will update the balance in table ‘try_event’ after every 5 minutes according to the balance and time at which the row is inserted.

EVENT code:

delimiter $$

CREATE EVENT `event`
ON SCHEDULE every 1 second  
DO 
begin
-- update balance by 2%
UPDATE try_event 
SET Balance = case 
WHEN timestampdiff(minute,date_created,current_timestamp) >0 and timestampdiff(minute,date_created,current_timestamp) MOD 5 = 0 and (balance>2000 and balance<3000) then Balance * 1.02 
end;
 end $$
delimiter ;

TABLE :

create table try_event(balance numeric(10,2) not null,date_created timestamp);

INSERTED ROWS:

insert into try_event values(2500,default);

insert into try_event values(1000,default);

but still it is giving the balance=2500 after 5 minutes.

When I remove “(balance>2000 and balance<3000)” the whole balance column is updated and result is:

2550

1020
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:06:20+00:00Added an answer on June 19, 2026 at 1:06 am

    I just created a test table on an instance of MySQL 5.5.29 (actually Percona Server, which is MySQL with some patches and new feature). It worked fine, it updated the 2500 balance and did not update the 1000 balance.

    Here’s a check that shows that the update happened (including automatically updating the TIMESTAMP column):

    mysql> SELECT timestampdiff(MINUTE, date_created, current_timestamp) AS td, 
                  balance FROM try_event;
    +------+---------+
    | td   | balance |
    +------+---------+
    |    8 |    1000 |
    |    3 |    2550 |
    +------+---------+
    

    I made slight changes to the event definition:

    When using CASE expressions, it’s worthwhile to represent an “ELSE” clause because otherwise if the WHEN condition is false, and you have no ELSE clause, the result of the CASE expression is just NULL.

    UPDATE try_event 
    SET Balance = CASE 
    WHEN timestampdiff(minute,date_created,current_timestamp) >0 
     AND timestampdiff(minute,date_created,current_timestamp) MOD 5 = 0 
     AND balance>2000 and balance<3000 
    THEN Balance * 1.02 
    ELSE Balance  -- this is what I added.
    END;
    

    Is it possible your balance column is declared NOT NULL, so the UPDATE is trying to set balance to NULL and it’s simply failing?

    I also remove the parentheses around the balance range comparison, but that shouldn’t make any difference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple SSIS package in which On Error event handler I have created
We have repositories which have a Save method. They also throw a Created event
I have an SQL script which creates a scheduled event: CREATE EVENT Daily_1200PM SCHEDULE
I have created tabs by using jQuery API and have bound one event handler
I have created an exe file as a part of pre build event. I
I am experimenting with Dart. I have created an on click event like so:
I have created a library which can download JSON data which is then placed
I have event manager process that dispatches events to subscribers (e.g. http_session_created, http_sesssion_destroyed). If
I have two auditing tables: Trip_aud and Event_aud. They were created in Envers, but
I have my server side code create an event on Facebook, using a Facebook

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.