MySQL 查询如何为表中的值设置不同的组合?

mysqlmysqli database

首先我们创建一个表 −

mysql> create table DemoTable622 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,Value1 int,Value2 int);
Query OK, 0 rows affected (1.08 sec)

使用 insert 命令在表中插入一些记录 −

mysql> insert into DemoTable622(Value1,Value2) values(1000,1000);
Query OK, 1 row affected (0.23 sec)
mysql> insert into DemoTable622(Value1,Value2) values(2000,3000);
Query OK, 1 row affected (1.04 sec)

使用 select 语句显示表中的所有记录 −

mysql> select *from DemoTable622;

这将产生以下输出 −

+----+--------+--------+
| Id | Value1 | Value2 |
+----+--------+--------+
|  1 | 1000   | 1000   |
|  2 | 2000   | 3000   |
+----+--------+--------+
2 rows in set (0.00 sec)

这是对 MySQL 组合的查询 −

mysql> select tbl1.Id,tbl2.Value1,tbl3.Value2 from DemoTable622 tbl1,DemoTable622 tbl2,DemoTable622 tbl3;

这将产生以下输出 −

+----+--------+--------+
| Id | Value1 | Value2 |
+----+--------+--------+
|  1 | 1000   |   1000 |
|  2 | 1000   |   1000 |
|  1 | 2000   |   1000 |
|  2 | 2000   |   1000 |
|  1 | 1000   |   3000 |
|  2 | 1000   |   3000 |
|  1 | 2000   |   3000 |
|  2 | 2000   |   3000 |
+----+--------+--------+
8 rows in set (0.01 sec)

相关文章