我无法理解笛卡尔积的工作原理.考虑简单的模式:
mysql> select * from account;
+----------------+-------------+---------+
| account_number | branch_name | balance |
+----------------+-------------+---------+
| A101 | Downtown | 500 |
| A102 | Perryridge | 400 |
| A201 | Brighton | 900 |
| A215 | Mianus | 700 |
| A217 | Brighton | 750 |
| A222 | Redwood | 700 |
| A305 | Round Hill | 350 |
+----------------+-------------+---------+
7 rows in set (0.00 sec)
现在,当我摆出查询
select a.balance from account a, account b where a.balance
除了最大值900外,我得到一系列值.然后使用not in运算符确定最大值.在上述查询之前,基于条件a.balance< b.balance进行联接时,关系中的第一个元组必须为500.理论上,前5个值必须为:
500
500
500
500
400
但是我得到:
+---------+
| balance |
+---------+
| 400 |
| 350 |
| 350 |
| 500 |
| 400 |
如何运作?我正在使用MySQL数据库.