1 aaa
2 BBB
3 CCC
4 DDD
5 the eee
6 FFFFF
7 KKKK
8 FDSF
If I want to put the name this list of all the field values of the random disturb how to write, such as id the name field value to be changed to id for 7 KKKK,
How do you write SQL statement, thank you, the good life of peace
CodePudding user response:
The name column with the order by the rand () exportThen the import
CodePudding user response:
So I don't know way doesn't work, copy the contents of the table now to another table (tab2), and then from the tab2 random reads a record as to change the value (for example may be a BBB, CCC, FFF,,, is possible), and then update your original table set name=value of random reads out the where id=1CodePudding user response:
DROP TABLE IF the EXISTS test;
CREATE TABLE test (id int primary key, name varchar (10));
Insert the test values
(1, "aaa"),
(2, 'BBB'),
(3, "CCC"),
(4, 'DDD),
(5, 'eee),
(6, 'FFFFF),
(7, 'KKKK'),
(8 'FDSF');
Update the test as the data, test the as ndata,
(
The SELECT aa. Id, bb. Id as nid
The FROM (SELECT id, @ a:=@ a + 1 as a the FROM (SELECT id FROM the test ORDER BY rand ()) d, (SELECT @ a:=0) a) aa,
(SELECT id, @ : b=@ b + 1 as b FROM the test d, b (SELECT @ : b=0) ORDER BY d.i d) bb
WHERE aa. A=bb. B
Nid)
Set the data. The name=ndata. Name
Where data. Id=nid. Id and nid. The nid=ndata. Id
;
Select * from the test;