0

我正在加入 mysql 中的表,但我有一张这样保存日期的表:

table: cutoff

      date       roomid  
---------------------------  
    2012-11-03     25
    2012-11-04     25
    2012-11-05     25
    2012-11-06     25

这是我的 SQL 查询:

SELECT t.RoomId, t.USD, t.MXN, i.Image, a.RoomName, a.RoomDesc, cu.date FROM Tarifas AS t 
INNER JOIN Images AS i ON i.RoomId = t.RoomId
INNER JOIN Availability AS a ON a.RoomId = t.RoomId 
INNER JOIN cutoff AS cu ON cu.roomid = t.RoomId AND cu.date NOT BETWEEN '$from' and '$to' 
WHERE t.Start <= '$from' AND t.End >= '$from' ORDER BY USD 

我想获取日期不在截止表中的所有行。但它给了我相反的东西!我不知道该怎么做,这里的任何帮助将不胜感激!

EIDT 添加关税表:

table: tarifas
RoomId      Start         End       USD       MXN
---------------------------------------------------
25        2012-11-01   2012-11-20   60.00    620.00
26        2012-11-01   2012-11-20   80.00    820.00
27        2012-11-01   2012-11-20   55.00    570.00
4

1 回答 1

1

试试这个(编辑):

SELECT t.RoomId, t.USD, t.MXN, i.Image, a.RoomName, a.RoomDesc
FROM Tarifas AS t 
INNER JOIN Images AS i ON i.RoomId = t.RoomId
INNER JOIN Availability AS a ON a.RoomId = t.RoomId 
WHERE t.RoomID NOT IN
    (SELECT DISTINCT roomid FROM cutoff
    WHERE date BETWEEN '$from' AND '$to')
AND t.Start <= '$from' AND t.End >= '$from'
ORDER BY USD 
于 2012-10-27T21:53:24.040 回答