简体   繁体   English

使用MyISAM表在mysql上递增多个值

[英]Using MyISAM table to increment multiple values on mysql

I have this table: cd_biblio which has a list of books. 我有此表:cd_biblio,其中具有书籍列表。

When I insert a new book from my php page, I want to increment a field ('Ingresso') based on the value 'Class' I inserted. 当我从php页面插入一本新书时,我想根据插入的值'Class'增加一个字段('Ingresso')。

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. 我插入一本类别为'A'的新书,他的'Ingresso'值将是该类'A'+ 1的当前'Ingresso'最大值。
How can I do this using MyISAM? 如何使用MyISAM执行此操作?

use prodedures or triggers fe: 使用程序或触发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 ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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