我有以下表格:
购物中心:
+-----------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------------+------+-----+---------+----------------+
| MallID | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| Name | varchar(45) | NO | | NULL | |
+-----------+----------------------+------+-----+---------+----------------+
店铺:
+------------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+---------+----------------+
| StoreID | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| MallID | smallint(5) unsigned | NO | MUL | NULL | |
| Name | varchar(45) | NO | | NULL | |
| Revenue | int(10) | NO | | NULL | |
+------------+----------------------+------+-----+---------+----------------+
顾客:
+------------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+---------+----------------+
| CustomerID | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| StoreID | smallint(5) unsigned | NO | MUL | NULL | |
| Name | varchar(45) | NO | | NULL | |
| Age | smallint(3) | NO | | NULL | |
+------------+----------------------+------+-----+---------+----------------+
Store.MallID
是的外键Mall.MallID
并且Customer.StoreID
是的外键Store.StoreID
1 - 我想选择所有商店总收入大于 100000 的 Mall。
select * from Mall where 100000 < ( select sum(Revenue) from Store where Mall.MallID = Store.MallID);
2 - 我想选择没有任何顾客的商场名称。
select Name from Mall where 0 = ( select count(*) from Customer, Store where Mall.MallID = Store.MallID and Store.StoreID = Customer.StoreID);
这些查询是否正确?