我需要从rooms_tbl表获取所有记录,并根据(状态)值从aqed_tbl表中获取一些记录 状态值:休息,忙碌,完成,删除
where state=rested or state=busy
我怎么能在一个视图中这样做???
答案 0 :(得分:0)
我想您的问题的答案是以下SQL:
select rm.*, ag.*
from rooms_tbl rm
inner join aged_tbl ag on rm.id = ag.room_id
where ag.state in ('rested', 'busy')
如果我们需要所有房间,即使他们没有age_tbl条目,那么此语句应该有外部联接:
select rm.*, ag.*
from rooms_tbl rm
left join aged_tbl ag on rm.id = ag.room_id
where ag.state in ('rested', 'busy')