I'm using SQL Server 2012.
I want to set sequential numbers to Num field each time I execute the SQL with the rules as follows:
- Grp order to be randomized.
- ID field to be ascended.
Could anyone shed some light for me?
TABLE
+-----+-----+----+
| Num | Grp | ID |
+-----+-----+----+
| 0 | 1 | 1 |
| 0 | 1 | 2 |
| 0 | 1 | 3 |
| 0 | 2 | 4 |
| 0 | 2 | 5 |
| 0 | 2 | 6 |
| 0 | 2 | 7 |
| 0 | 3 | 8 |
| 0 | 3 | 9 |
| 0 | 4 | 10 |
| 0 | 4 | 11 |
| 0 | 4 | 12 |
| 0 | 4 | 13 |
| 0 | 4 | 14 |
+-----+-----+----+
EXPECTED OUTPUT
+-----+-----+----+
| Num | Grp | ID |
+-----+-----+----+
| 1 | 3 | 8 |
| 2 | 3 | 9 |
| 3 | 1 | 1 |
| 4 | 1 | 2 |
| 5 | 1 | 3 |
| 6 | 4 | 10 |
| 7 | 4 | 11 |
| 8 | 4 | 12 |
| 9 | 4 | 13 |
| 10 | 4 | 14 |
| 11 | 2 | 4 |
| 12 | 2 | 5 |
| 13 | 2 | 6 |
| 14 | 2 | 7 |
+-----+-----+----+