要获取随机整数范围,请使用rand()
函数。创建表的查询-
mysql> create table RandomIntegerDemo −> ( −> Number int −> );
将记录插入表中。查询如下-
mysql> insert into RandomIntegerDemo values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14); Records: 14 Duplicates: 0 Warnings: 0
现在,您可以在select语句的帮助下显示所有记录。查询如下-
mysql> select *from RandomIntegerDemo;
以下是显示整数的输出-
+--------+ | Number | +--------+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | | 11 | | 12 | | 13 | | 14 | +--------+ 14 rows in set (0.00 sec)
生成随机整数范围的查询如下-
mysql> select Number, (FLOOR( 1 + RAND( ) *14 )) AS RandomValue −> from RandomIntegerDemo −> limit 0,14;
输出在同一表中显示随机整数范围-
+--------+-------------+ | Number | RandomValue | +--------+-------------+ | 1 | 9 | | 2 | 8 | | 3 | 13 | | 4 | 13 | | 5 | 10 | | 6 | 10 | | 7 | 7 | | 8 | 3 | | 9 | 8 | | 10 | 2 | | 11 | 14 | | 12 | 6 | | 13 | 3 | | 14 | 9 | +--------+-------------+ 14 rows in set (0.00 sec)