sql - Automatically update record using if else in mysql table -


i new mysql , need help.

to make clearer, have 3 columns in mysql table;

  1. date of membership
  2. membership expiry
  3. membership status

1st , 2nd column using date format. , 3rd column using varchar.

so, i'm trying is, if expiry date exceed current date, record of 3rd column automatically changed 'expired'. , if not exceed, display 'active'.

is possible?

really appreciate if can help.

mysql supports events. helpful when not want manually check status of each record.

example code:

delimiter $$ create event `update_status` on schedule every 1 hour  begin     update tablename     set membershipstatus = if(curdate() > membershipexpiry, 'expired', 'active'); end $$ delimiter ; 

what statement after script has been created, fired every 1 hour interval.

to lean more events, please see links below.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -