我需要在Room No
上加入两个表值。
以下是我的表格:
RoomStatusTable
----------------------------------------------------
| Room No | Type | Date | Descriprion |
----------------------------------------------------
| 1 | AC |22 Jan 2015| VA |
| 2 | AC |22 Jan 2015| VA |
| 3 | AC |22 Jan 2015| VA |
| 4 | AC |22 Jan 2015| VA |
RoomBooked Table
----------------------------------------------------
| Room No | Type | Date | Descriprion |
----------------------------------------------------
| 1 | AC |22 Jan 2015| BK001 |
| 2 | AC |22 Jan 2015| BLOCK |
| 4 | AC |22 Jan 2015| OC001 |
我需要如下结果:
----------------------------------------------------
| Room No | Type | Date | Descriprion |
----------------------------------------------------
| 1 | AC |22 Jan 2015| BK001 |
| 2 | AC |22 Jan 2015| Block |
| 3 | AC |22 Jan 2015| VA |
| 4 | AC |22 Jan 2015| OC001 |
与此类似,表1包含所有记录,但是,表2仅包含基于该更改描述的占用记录作为我的结果。
答案 0 :(得分:3)
使用Left join
从两个表中获取数据:
select r1.room_no,
r1.Type,
r1.Date,
case when r2.Descriprion is null then r1.Descriprion else r2.Descriprion end as description
from RoomStatus r1
left join RoomBooked r2 on r1.room_no=r2.room_no
order by r1.room_no;
答案 1 :(得分:0)
使用Coalesce函数返回两个描述列之间的第一个非null值,
...
success: function (data) {
alert("hotels: " + data.hotels + "\nrooms: " + data.rooms);
}