Of course, at the end of my code there is a mistake, not in the real sense of random data. Back home, quickly Baidu, this just know how to randomly access data.
The rest of the code is not much to say, here's how to tell you the core Lookup data table code:
| The code is as follows |
|
SELECT * FROM table name ORDER by rand () limit 1; The 1 here is the number of strips that take out the data |
But this data on the Internet, some people say the efficiency is very poor, then how to improve it
Search Google, the Internet is basically query Max (ID) * RAND () to randomly obtain data.
| The code is as follows |
|
SELECT * From ' table ' as T1 JOIN (select ROUND (RAND () * (SELECT MAX (ID) from ' table ') as ID) as T2 WHERE t1.id >= t2.id ORDER BY T1.id ASC LIMIT 5; |
But this gets the 5 consecutive records. The solution can only be a query one at a time, query 5 times, but this is not enough to meet my requirements, I want to find a few
Efficient writing
| code is as follows |
&nbs P; |
| Select * from user WHERE userId >= ((SELECT MAX (userId) F ROM user)-(select min (userId) from user) * RAND () + (select min (userId) from user) LIMIT 5 |