我不确定我需要什么样的连接,因为我不熟悉尝试以这种方式重叠数据,或者它是否可行。
我有两个表,它们都共享一组相似的数据,并且都与第三个父表相关Room_id.
我有一个名为 Room_rates 的表,它存储每个房间的平均价格(room_id)
+-------+---------+-----------+-------+--------+---------------------------+---------------------------+
| id | room_id | dayofweek | price | source | created_at | updated_at |
+-------+---------+-----------+-------+--------+---------------------------+---------------------------+
| 87936 | 2517 | 0 | 14.58 | 1 | 2010-02-22 17:47:14 +0100 | 2010-02-22 17:47:14 +0100 |
| 87937 | 2517 | 1 | 14.58 | 1 | 2010-02-22 17:47:14 +0100 | 2010-02-22 17:47:14 +0100 |
| 87938 | 2517 | 2 | 14.52 | 1 | 2010-02-22 17:47:14 +0100 | 2010-02-22 17:47:14 +0100 |
| 87939 | 2517 | 3 | 14.52 | 1 | 2010-02-22 17:47:14 +0100 | 2010-02-22 17:47:14 +0100 |
| 87940 | 2517 | 4 | 14.52 | 1 | 2010-02-22 17:47:15 +0100 | 2010-02-22 17:47:15 +0100 |
| 87941 | 2517 | 5 | 14.4 | 1 | 2010-02-22 17:47:15 +0100 | 2010-02-22 17:47:15 +0100 |
| 87942 | 2517 | 6 | 14.63 | 1 | 2010-02-22 17:47:15 +0100 | 2010-02-22 17:47:15 +0100 |
+-------+---------+-----------+-------+--------+---------------------------+---------------------------+
还有一个名为 Availables 的表,其中包含特定日期的费率
+--------+-------+-------+------------+---------+---------------------------+---------------------------+--------+
| id | price | spots | bookdate | room_id | created_at | updated_at | source |
+--------+-------+-------+------------+---------+---------------------------+---------------------------+--------+
| 221389 | 14.3 | 1 | 2010-03-01 | 2517 | 2010-02-21 22:31:06 +0100 | 2010-02-21 22:31:06 +0100 | 1 |
| 221390 | 14.3 | 1 | 2010-03-02 | 2517 | 2010-02-21 22:31:06 +0100 | 2010-02-21 22:31:06 +0100 | 1 |
| 221391 | 14.3 | 1 | 2010-03-03 | 2517 | 2010-02-21 22:31:06 +0100 | 2010-02-21 22:31:06 +0100 | 1 |
| 221392 | 14.3 | 1 | 2010-03-04 | 2517 | 2010-02-21 22:31:06 +0100 | 2010-02-22 17:47:19 +0100 | 1 |
| 221393 | | 0 | 2010-03-05 | 2517 | 2010-02-21 22:31:06 +0100 | 2010-02-22 17:47:19 +0100 | 1 |
| 221394 | | 0 | 2010-03-06 | 2517 | 2010-02-21 22:31:06 +0100 | 2010-02-22 17:47:19 +0100 | 1 |
| 228185 | | 0 | 2010-03-07 | 2517 | 2010-02-22 17:47:19 +0100 | 2010-02-22 17:47:19 +0100 | 1 |
| 228186 | 14.3 | 1 | 2010-03-08 | 2517 | 2010-02-22 17:47:19 +0100 | 2010-02-22 17:47:19 +0100 | 1 |
| 228187 | 14.3 | 1 | 2010-03-09 | 2517 | 2010-02-22 17:47:19 +0100 | 2010-02-22 17:47:19 +0100 | 1 |
| 228188 | 14.3 | 1 | 2010-03-10 | 2517 | 2010-02-22 17:47:19 +0100 | 2010-02-22 17:47:19 +0100 | 1 |
+--------+-------+-------+------------+---------+---------------------------+---------------------------+--------+
目前我正在使用两个单独的搜索结果,Availables
特定日期范围的当前数据存在或不存在。如果不是,我使用仅使用Room_rate
平均值的备份查询。
我想在有可用价格的地方使用 Availables,但如果价格不可用或可能根本没有记录,我想以某种方式加入 Room_rates 来填补空白。
我怎么能做到这一点?