我有這張表,我想把它分成三張表,所以我有名稱,名稱和訂單之間的關係表,以及第三個只包含訂單。所以,我認爲一個簡單的方法可能是在這裏補充一個唯一的編號列MYSQL:基於唯一的行值爲表添加唯一的數值?
+----+------+-----------------------+-------+--------------+
| id | name | address | phone | order_number |
+----+------+-----------------------+-------+--------------+
| 1 | Joe | Joes Address | 1111 | 1390842 |
| 2 | Paul | Pauls Address | 2222 | 9082309 |
| 3 | Greg | Gregs Address | 3333 | 0928340 |
| 4 | Lucy | Lucys Address | 4444 | 9028340 |
| 5 | Paul | Pauls Address | 2222 | 8958399 |
| 6 | Tom | Toms Address | 5555 | 9084024 |
| 7 | Lucy | Lucys Another Address | 4444 | 9801983 |
| 8 | Paul | Pauls Another Address | 2222 | 0982304 |
+----+------+-----------------------+-------+--------------+
,我想用獨特的name
值相關聯的遞增的數字添加數字列,使該預期的結果
+----+------+-----------------------+-------+--------------+---+
| id | name | address | phone | order_number |NID|
+----+------+-----------------------+-------+--------------+---|
| 1 | Joe | Joes Address | 1111 | 1390842 | 1 |
| 2 | Paul | Pauls Address | 2222 | 9082309 | 2 |
| 3 | Greg | Gregs Address | 3333 | 0928340 | 3 |
| 4 | Lucy | Lucys Address | 4444 | 9028340 | 4 |
| 5 | Paul | Pauls Address | 2222 | 8958399 | 2 |
| 6 | Tom | Toms Address | 5555 | 9084024 | 5 |
| 7 | Lucy | Lucys Another Address | 4444 | 9801983 | 4 |
| 8 | Paul | Pauls Another Address | 2222 | 0982304 | 2 |
+----+------+-----------------------+-------+--------------+---+
我該怎麼做?
你只是想顯示NID作爲查詢結果或想要添加表中的列嗎? –