samedi 18 juillet 2015

Update a increasing value by SQL

I have a table, data like this:

+-----------+--------------------------------------+-------+
| address   | subnet_id                            | major |
+-----------+--------------------------------------+-------+
| 1.1.1.1   | 20287949-018b-4036-b849-812de91bd95e |     0 |
| 1.1.1.1   | 55a3f8f0-8a2b-47b5-a610-62498bdc0e30 |     0 |
| 1.2.2.3   | 55a3f8f0-8a2b-47b5-a610-62498bdc0e30 |     0 |
| 2.2.2.2   | 20287949-018b-4036-b849-812de91bd95e |     0 |
| 2.2.2.2   | 7ec1f191-476d-46cd-8fc9-0a8d24dfb8e9 |     0 |
| 3.3.3.3   | 20287949-018b-4036-b849-812de91bd95e |     0 |
| 7.7.7.7   | 7ec1f191-476d-46cd-8fc9-0a8d24dfb8e9 |     0 |
| 9.99.9.10 | 7ec1f191-476d-46cd-8fc9-0a8d24dfb8e9 |     0 |
+-----------+--------------------------------------+-------+

I need to update major column to a increasing number (from 0 to 1, 2, 3...) . For a example, update subnet_id equals'7ec1f191-476d-46cd-8fc9-0a8d24dfb8e9'. The result should be like this:

+-----------+--------------------------------------+-------+
| address   | subnet_id                            | major |
+-----------+--------------------------------------+-------+
| 2.2.2.2   | 7ec1f191-476d-46cd-8fc9-0a8d24dfb8e9 |     0 |
| 7.7.7.7   | 7ec1f191-476d-46cd-8fc9-0a8d24dfb8e9 |     1 |
| 9.99.9.10 | 7ec1f191-476d-46cd-8fc9-0a8d24dfb8e9 |     2 |
+-----------+--------------------------------------+-------+

What should I do by SQL?

Aucun commentaire:

Enregistrer un commentaire