简体   繁体   中英

Using MyISAM table to increment multiple values on mysql

I have this table: cd_biblio which has a list of books.

When I insert a new book from my php page, I want to increment a field ('Ingresso') based on the value 'Class' I inserted.

For example:
I insert a new book with class 'A', his 'Ingresso' value will be the current max of 'Ingresso' for the class 'A' + 1.
How can I do this using MyISAM?

use prodedures or triggers fe:

delimiter ~
CREATE PROCEDURE AddBook(...)
BEGIN
  DECLARE gIngresso INT DEFAULT 0;
  SELECT Max(Ingresso) INTO gIngresso FROM Table;
  INSERT INTO Table VALUE(... , gIngresso)
END~

delimiter ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM