【发布时间】:2013-05-09 10:29:26
【问题描述】:
在 MySQL 中:
假设我有这张桌子:
id | name | count |
1 | John | |
2 | John | |
3 | John | |
4 | Mary | |
5 | Lewis| |
6 | Lewis| |
7 | Max | |
8 | Max | |
名称已经分组,因此相同的名称会出现在一起。 现在我希望表格是这样的:
id | name | count |
1 | John | 1 |
2 | John | 2 |
3 | John | 3 |
4 | Mary | 1 |
5 | Lewis| 1 |
6 | Lewis| 2 |
7 | Max | 1 |
8 | Max | 2 |
请注意,每次重复同名时,它都会自动增加 count 的值。
谢谢!
【问题讨论】:
-
您希望该列在表中具体化,还是只想将该列作为查询/视图的结果?