Home > database >  MYSQL zha yao sample after get grouped random 2 data online, such as the great god!!!!!!
MYSQL zha yao sample after get grouped random 2 data online, such as the great god!!!!!!

Time:09-28

One table there are five groups of zha yao implementation for each group of random 2 data

Have a great god to answer yo


-
- table structure ` table_3 `
-

The CREATE TABLE ` table_3 ` (
` id ` int (11) NOT NULL,
` name ` varchar (30) CHARACTER SET utf8 DEFAULT NULL,
` zu ` int (11), NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-
- archived data in a table ` table_3 `
-

INSERT INTO ` table_3 ` (` id `, ` name `, ` zu `) VALUES
(1, 3, 1),
(2, 'bill', 2),
(3, '5' 3),
(4, 'li si, 4),
(5, '6', 5),
(6, 'li 12, 5),
(7, 'pieces of eight, 3),
(8, '1' li, 4),
(9 '1234', 2),
(10, 'li' 1 ', 1),
(11, '34', 2),
(12, 'li 1 gg, 1),
(13, 'zhang 34 gg, 3),
(14, 'li 1 GGGGG, 4),
(15, 'zhang 34 ggi, 5),
(16, 'lee GFFGG 1, 3),
(17, '321321', 2),
(18, '321321', 1),
(19, 'FFFF, 3),
(20, 'GGHHH, 4),
(21, 'ddsad, 5),
(22, 'FFSDDS', 1),
(23, 'drops', 3),
(24, 'fat fat, 4),
(25, "flower", 1),
(26, "flower", 4);

CodePudding user response:

Select * from table_3 order by rand (limit 2)

CodePudding user response:

 
With the tx as (
Select t. *, row_number () over (partition by t.z u order by t.i d) Rn
The from table_3 t
) select * from tx where tx. Rn<=4;





PS: version should be above mysql8.0,
  • Related