I am new to SQL and I am confronted with a hopefully easy to solve Problem:
Currently my view looks like this:
Credittype | Person |
---|---|
Type 1 | James |
Type 2 | Jose |
Type 2 | Mike |
Now I want to duplicate each row in this example 2 times, and give each copied row a new number.
The resulting table should look like this:
Credittype | Person | Number |
---|---|---|
Type 1 | James | 1 |
Type 1 | James | 2 |
Type 1 | James | 3 |
Type 2 | Jose | 1 |
Type 2 | Jose | 2 |
Type 2 | Jose | 3 |
Type 2 | Mike | 1 |
Type 2 | Mike | 2 |
Type 2 | Mike | 3 |
An easy solution would be something like:
Select Credittype, Person, "1" AS Number from table
union all
Select Credittype, Person, "2" AS Number from table
union all
Select Credittype, Person, "3" AS Number from table
The problem is that in reality I need to copy those rows 50 times... I think there is a more efficient way to solve this problem.