如果某一行存在于另一个表中的某一天和某个句点中,则从该表中省略一行

时间:2013-02-19 19:58:44

标签: mysql

我正在尝试编写一个查询,如果在某个日期/某个时间发现,则会忽略另一个表中的行,但如果存在,则会包含该行。

它当前省略了该行,但如果在某一天/时间没有找到则不包含该行。我怎么能纠正这个?

SELECT * FROM ts_room
WHERE
id <>
(SELECT status
FROM ts_request rq
LEFT JOIN ts_allocation a ON a.request_id = rq.id
WHERE 
day_id=1 AND period_id=2
OR a.status IS NOT NULL
AND a.status IN ('Pending','Declined','Failed')) 

这是我的SQL小提琴http://sqlfiddle.com/#!2/c8da9/49

0 个答案:

没有答案