0
Write a query in SQL that uses a random number generator to create a variable integer to determine the amount of rows selected.
2 Answers
0
---- Create the variables for the random number generation
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
---- This will create a random number between 1 and 999
SET @Lower = 1 ---- The lowest random number
SET @Upper = 999 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SELECT @Random
+ 1
Try using function rand(), which generates a random float number between 0.0 and 1.0 (1.0 not included), and the keyword LIMIT.