1
我想了解在mysql中嵌套查詢和我被困在選擇所有酒店 這是從城市30英里,且有房,成本150 $MySQL中的嵌套查詢問題
我可以選擇了距離城市30英里的房間,使用此查詢花費150美元,但無法到達酒店。
(select id from Rooms where cost = 150 and id in
(select r_id from has_rooms where name IN (select name from is_at where l_town in
(select town from Location where distance_from_city = 30))));
Rooms
+----+------+---------+
| id | cost | type |
+----+------+---------+
| 1 | 100 | kral |
| 2 | 0 | kralice |
| 3 | 150 | padisah |
| 4 | 150 | hop |
| 5 | 150 | boss |
+----+------+---------+
has_rooms
+------+------+
| r_id | name |
+------+------+
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | A |
| 3 | A |
+------+------+
is_at
+------+----------+
| name | l_town |
+------+----------+
| A | istanbul |
| B | izmir |
| C | kars |
| D | adana |
+------+----------+
select * from Location;
+--------------------+----------+----------------+----------+
| distance_from_city | postcode | street | town |
+--------------------+----------+----------------+----------+
| 30 | NULL | KENNEDY Street | istanbul |
| 35 | NULL | NULL | kars |
| 40 | NULL | Tenesse | izmir |
| 50 | NULL | NULL | adana |
+--------------------+----------+----------------+----------+
Hotel
+------+--------+
| name | rating |
+------+--------+
| A | 5 |
| B | 5 |
| C | 4 |
| D | 1 |
+------+--------+
以及我的目的是用嵌套查詢來解決這個問題:) – iva123 2010-01-11 17:01:12