另一個表匹配結果添加列這是我在choosen期間可用客房查詢:從第一MySQL查詢
SELECT rooms.room_id
FROM rooms
WHERE rooms.room_id NOT IN (
SELECT reservations.room_id
FROM reservations
WHERE ( reservations.arrivaldate >= $arrival_datetime
AND reservations.departuredate <= $departure_datetime
)
OR ( reservations.arrivaldate <= $arrival_datetime
AND reservations.departuredate >= $arrival_datetime
)
OR ( reservations.arrivaldate <= $departure_datetime
AND reservations.departuredate >= $departure_datetime
)
);
如何爲選定時段(arrival_datetime departure_datetime從$至$)加平均房價柱從另一個表(room_prices_table)中,查詢從上面返回的每個room_id。所以,我需要在列看看衛生組織的名字是一樣的... ROOM_ID
room_prices_table:
date
room0001
room0002
room0003
...
喜歡的東西
SELECT AVG(room0003)
FROM room_prices_table
WHERE datum IS BETWEEN $arrival_datetime
AND $departure_datetime
?
這是功課嗎?看起來很像一個表哥http://stackoverflow.com/questions/2269556/retrieving-specific-tuples-using-mysql – lexu 2010-05-05 04:36:56
@lexu:很好的觀察。看起來有一個班正在進行這個項目:-D – bernie 2010-05-05 04:43:27
@Adam Bernier:那也是我的印象。不過,他的問題不同於自己。但在其他問題中的reservation_range/free_range檢測比他在這裏展示的(3 ORs!,yuck)更好。 – lexu 2010-05-05 05:18:36