当前表不是为增长而设置的,我想将现有数据迁移到更适合扩展的表中。让我解释:
当前表设置如下:
+--------+---------------+----+----+----+------+-----------+
| id | DateOfService | AM | MD | PM | RATE | CLIENT_ID |
+--------+---------------+----+----+----+------+-----------+
| 1 | 3/4/2013 | 1 | 0 | 0 | 10 | 123 |
| 2 | 3/5/2013 | 1 | 0 | 0 | 10 | 123 |
| 3 | 3/6/2013 | 1 | 0 | 0 | 10 | 123 |
| 4 | 3/5/2013 | 0 | 1 | 1 | 50 | 147 |
| 5 | 3/6/2013 | 1 | 1 | 1 | 25 | 189 |
+--------+---------------+----+----+----+------+-----------+
相反,我想像这样设置我的表:
+----------+---------------+---------------+-----------+
| pkid | DateOfService | ServiceTypeID | CLIENT_ID |
+----------+---------------+---------------+-----------+
| 1 | 3/4/2013 | 1 | 123 |
| 2 | 3/5/2013 | 1 | 123 |
| 3 | 3/6/2013 | 1 | 123 |
| 4 | 3/5/2013 | 2 | 147 |
| 5 | 3/5/2013 | 3 | 147 |
| 6 | 3/6/2013 | 1 | 189 |
| 7 | 3/6/2013 | 2 | 189 |
| 8 | 3/6/2013 | 3 | 189 |
+----------+---------------+---------------+-----------+
ServiceTypeID 表将是一个options
表设置,例如:
+-------------------+---------+
| ServiceTypeID | Service |
+-------------------+---------+
| 1 | AM |
| 2 | MD |
| 3 | PM |
+-------------------+---------+
我需要帮助提出一个可以运行的查询,该查询将选择并循环现有数据并填充我的新表。