mysql的随机查询

SELECT * FROM tablename ORDER BY RAND() LIMIT 10sql

让咱们去Mysql的官网去看看,这个内置函数。 RAND([N])express

Returns a random floating-point value v in the range 0 <= v < 1.0. To obtain a random integer R in the range i <= R < j, use the expression FLOOR(i + RAND() * (j − i)). For example, to obtain a random integer in the range the range 7 <= R < 12, use the following statement:dom

SELECT FLOOR(7 + (RAND() * 5)); If an integer argument N is specified, it is used as the seed value:函数

With a constant initializer argument, the seed is initialized once when the statement is prepared, prior to execution.this

With a nonconstant initializer argument (such as a column name), the seed is initialized with the value for each invocation of RAND().ci

One implication of this behavior is that for equal argument values, RAND(N) returns the same value each time, and thus produces a repeatable sequence of column values. In the following example, the sequence of values produced by RAND(3) is the same both places it occurs. 根据介绍,能够看出这就是个获取0-1之间随机数的函数。 不过这种应该能够知足随机取出数据的要求。it

相关文章
相关标签/搜索