mysql> create table a select 1 union select 2 union select 3 union select 4;
mysql> select count(*) from a, a a2, a a3, a a4;
+----------+
| count(*) |
+----------+
| 256 |
+----------+
1 row in set (0.01 sec)
mysql> select count(*) from a, a a2, a a3, a a4, a a5, a a6;
+----------+
| count(*) |
+----------+
| 4096 |
+----------+
1 row in set (0.00 sec)
mysql> drop table a; /* 一旦、テーブル消します */
Query OK, 0 rows affected (0.03 sec)
mysql> create table a select 1 union select 2; /* 2件データを作ります。 */
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into a (select a.1 from a, a a1, a a2); /* 2 * 2 * 2 = 8 件追加 */
Query OK, 8 rows affected (0.03 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> select count(*) from a;
+----------+
| count(*) |
+----------+
| 10 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from a, a a2, a a3, a a4, a a5, a a6, a a7;
+----------+
| count(*) |
+----------+
| 10000000 |
+----------+
1 row in set (0.00 sec)
SET @range_from := 1;
SET @range_to := 6;
select floor(rand() * (@range_to - @range_from + 1) + @range_from) ;
select floor(rand() * 6 + 1) ;
mysql> select num, count(*), count(*) / 10000000 * 100 from
-> (select floor(rand() * 6 + 1) num from a, a a2, a a3, a a4, a a5, a a6, a a7 ) dat
-> group by 1
-> ;
+------+----------+---------------------------+
| num | count(*) | count(*) / 10000000 * 100 |
+------+----------+---------------------------+
| 1 | 1665735 | 16.6574 |
| 2 | 1667785 | 16.6779 |
| 3 | 1666653 | 16.6665 |
| 4 | 1665520 | 16.6552 |
| 5 | 1668201 | 16.6820 |
| 6 | 1666106 | 16.6611 |
+------+----------+---------------------------+
6 rows in set (7.49 sec)
SET @id := 0;
create table data
select @id := @id + 1 id , num from
(select floor(rand() * 6 + 1) num from a, a a2, a a3, a a4, a a5, a a6, a a7 ) dat
mysql> select * from data limit 10;
+------+------+
| id | num |
+------+------+
| 1 | 6 |
| 2 | 1 |
| 3 | 2 |
| 4 | 2 |
| 5 | 5 |
| 6 | 6 |
| 7 | 6 |
| 8 | 2 |
| 9 | 3 |
| 10 | 4 |
+------+------+
10 rows in set (0.02 sec)