SELECT Br.BusinessDivision,B.BookingDate, B.DepartureDate, B.CustomerID, C.FirstName, C.SurName
FROM Booking B
INNER JOIN Customer C
ON C.ContactID = B.ContactID
INNER JOIN Branch Br
ON Br.BranchID = B.BranchID
WHERE B.BookingDate
BETWEEN '2015-04-01' AND '2018-04-26'
AND Br.BusinessDivision IN ( 'Retail', 'TVSales' )
AND B.ContactID NOT IN (
SELECT B.DepartureDate FROM Booking B WHERE B.DepartureDate >= '2018-04-26'
);
以下SQL语句给出了以下错误:error Operand type clash: date is incompatible with int
日期列B.BookingDate
和B.DepartureDate
都是数据类型date
而不是int
所以我不确定为什么会收到此错误?
答案 0 :(得分:1)
AND B.ContactID NOT IN ( SELECT B.DepartureDate
您正在将ContactID
(可能是一个int)与DepartureDate
进行比较,大概是一个约会。
我想你想要:
AND B.ContactID NOT IN
(
SELECT B.CustomerID FROM Booking B
WHERE B.DepartureDate >= '2018-04-26'
);