I ran into a peculiar problem today when I wanted to migrate the history data for a table.
I have a table which stores the number of downloads of one type content (say wallpapers). This is the old ‘downloads’ table structure –
Content_ID Download_Count
1 3
2 5
3 20
4 1
5 7
Now, I realize that this table does not have any information about when the download was made. So, now I am creating a new table with the following structure.
Content_ID Download_Time
1 0
1 0
1 0
2 0
2 0
2 0
2 0
2 0
3 0
3 0
3 0 etc
In the new table structure, the number of times a Content_ID appears will say the number of downloads. Now I want to move the existing data to this table. For that, a query is needed. The query should generate the data for the new table from the old table data. For example, if Content_ID has 3 downloads, we need to insert 3 records in to the new table. Similarly, we need to insert 5 records for Content_ID 2 etc. How to generate a output like this in a query?
I use mysql.
With a table of numbers (from 1 or 0 up to a high enough value) you can do a query like this.