sql - insert data using counters in mysql -
i have data set in mysql:
p_id c_id amount 5 1 2000 6 1 3000 7 1 4000
i need insert same data in table, , increment counter of c_id 1 till 7.
so, in there 21 entries total.
how can sql??
result:
p_id c_id amount 5 1 2000 6 1 3000 7 1 4000 5 2 2000 6 2 3000 7 2 4000 5 3 2000 6 3 3000 7 3 4000 5 4 2000 6 4 3000 7 4 4000
c_id can go till 9.
is want?
insert t(p_id, c_id, amount) select t.p_id, c.c_id, t.amount t cross join (select 2 c_id union select 3 union select 4 union select 5 union select 6 union select 7 ) c;
Comments
Post a Comment