mysql SELECT with autoincrement variable
I wanted to get value of a column in mysql, but with serial number.I got the answer here: http://bytes.com/groups/mysql/74731-auto-increment-fly
mysql> select @cn:=0;
+--------+
| @cn:=0 |
+--------+
| 0 |
+--------+
1 row in set (0.00 sec)
Then do
mysql> select duration, @cn:=@cn+1 as cc from vod limit 10;
+----------+------+
| duration | cc |
+----------+------+
| 3592 | 1 |
| 1705 | 2 |
| 2966 | 3 |
| 2982 | 4 |
| 2986 | 5 |
| 3580 | 6 |
| 2970 | 7 |
| 2971 | 8 |
| 1702 | 9 |
| 2965 | 10 |
+----------+------+
10 rows in set (0.00 sec)
Labels: mysql