Red de conocimiento informático - Problemas con los teléfonos móviles - tp5? ¿Cómo obtener aleatoriamente n datos?

tp5? ¿Cómo obtener aleatoriamente n datos?

1. Leer aleatoriamente varios registros consecutivos. Después de la práctica, se pueden leer aleatoriamente varios registros de datos consecutivos. Los valores que contienen suelen ser la ID de la clave principal para leer los valores máximo y mínimo:

1

SELECT.

*

DESDE

example_table

COMO

t1

UNIRSE

(SELECT

ROUND(RAND()

*

((SELECT

MAX(id)

DESDE

example_table)-(SELECCIONAR

MIN(id)

DESDE

example_table)) (SELECCIONAR

MIN(id)

DESDE

example_table))

COMO

id)

COMO

t2

DONDE

t1.id

gt;=

t2.id

ORDEN

POR

t1.id

LÍMITE

5;

2 Múltiples datos aleatorios. Los dos métodos siguientes leen datos de forma aleatoria y la velocidad de los datos de consulta y el rango aleatorio son básicamente los mismos

1

SELECT

*

DESDE

tabla_ejemplo

DONDE

id

gt; =

((SELECCIONAR

MAX(id)

DESDE

example_table)-(SELECT

MIN(id)

DESDE

example_table))

*

RAND()

(SELECT

MIN( id )

DESDE

example_table)

LÍMITE

5;

1

SELECCIONAR

*

DESDE

example_table

DÓNDE

idgt;=(SELECCIONAR

suelo(RAND()

*

((SELECT

MAX(id)

DESDE

example_table)-(SELECCIONAR

MIN(id)

DESDE

example_table))

( SELECCIONAR

MIN(id)

DESDE

example_table)))

ORDEN

POR

p>

id

LÍMITE

5;