jeudi 3 octobre 2019

MYSQL: Duplicate data from tables randomly and setting the size

I want to duplicate this data:

df1
COL1    COL2    COL3
A   1   A1
B   2   A1
C   3   B1
D   4   B1
E   5   A1

if i want duplicate all data the script:

insert into .. 
select * from df1
where COL3 = 'A1'
order by rand()

But all i want is duplicate only 2 of 5 data where COL3=A1 (not all data) and choose randomly. Example of the result:

df2
COL1    COL2    COL3
A   1   A1
B   2   A1
C   3   B1
D   4   B1
E   5   A1
B   2   A1
E   5   A1

there is a way to get the result like df2?




Aucun commentaire:

Enregistrer un commentaire