我有一张这样的table
+------------------+------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+-------------------+-----------------------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(10) unsigned | NO | | NULL | |
| arena_ids | json | NO | | NULL | |
| organization_id | int(10) unsigned | NO | MUL | NULL | |
| type | tinyint(4) | NO | | NULL | |
| registration_fee | double | YES | | NULL | |
| tax_group_id | int(10) unsigned | YES | MUL | NULL | |
| from_date | date | YES | | NULL | |
| to_date | date | YES | | NULL | |
| status | varchar(10) | YES | | NULL | |
| comments | varchar(100) | YES | | NULL | |
| created_at | datetime | NO | | CURRENT_TIMESTAMP | |
| updated_at | datetime | YES | | NULL | on update CURRENT_TIMESTAMP |
| deleted_at | datetime | YES | | NULL | |
+------------------+------------------+------+-----+-------------------+-----------------------------+
现在在这个表中,我必须再添加一列 serial number
然后呢 serial number
威尔 auto_increment
但在我的情况下,我必须增加一些不同的东西 serial_number
直到 organization_id
改变,如果 organization_id
现在又变了 serial_number
从1开始。
`serial_number` `organization_id`
1 1
2 1
1 2
3 1
2 2
当我在阅读文档时,我发现了一些这样的例子,但我在这里我必须更新而不是创建
CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
)
+--------+----+---------+
| grp | id | name |
+--------+----+---------+
| fish | 1 | lax |
| mammal | 1 | dog |
| mammal | 2 | cat |
| mammal | 3 | whale |
| bird | 1 | penguin |
| bird | 2 | ostrich |
+--------+----+---------+
如何在更新查询中实现这一点。
暂无答案!
目前还没有任何答案,快来回答吧!