0

我被困在一条 SQL 语句上。我正在尝试获得以下信息:

Select fields from the rentedHouseTbl WHERE

一个属性匹配一个属性IDTr

**AND**

    the rentedHouseMoveInDateTr is less than or equal to today's date AND
    the rentedHouseMoveOutDateTr is NULL 

    OR

    the rentedHouseMoveInDateTr is less than or equal to today's date AND 
    the rentedHouseMoveOutDateTr is greater than today's date.

If this returns results then the property is occupied
else it is vacant

我使用的 SQL 语句是:

SELECT * FROM rentedHouseTbl where propertyIDTr = '1' AND ( (rentedHouseMoveInDateTr <= CURDATE() AND rentedHouseMoveOutDateTr IS NULL) OR (rentedHouseMoveInDateTr <= CURDATE() AND rentedHouseMoveOutDateTr > CURDATE()) )

但我没有得到预期的结果。任何帮助,将不胜感激!

4

3 回答 3

0

请试试这个:

SELECT * FROM rentedHouseTbl 
  WHERE propertyIDTr = '1' 
     AND rentedHouseMoveInDateTr <= CURDATE() 
     AND ISNULL(rentedHouseMoveOutDateTr, DATE_ADD(CURDATE(), INTERVAL -1 DAY)) <> CURDATE()
于 2019-12-06T23:34:40.100 回答
0

尝试这个:

SELECT * FROM rentedHouseTbl 
where 
where propertyIDTr = '1'and
rentedHouseMoveInDateTr <= CURDATE() AND (rentedHouseMoveOutDateTr IS NULL or rentedHouseMoveOutDateTr > CURDATE())  
于 2019-12-06T23:15:53.613 回答
-1
SELECT * FROM rentedHouseTbl 
where (rentedHouseMoveInDateTr <= CURDATE() AND rentedHouseMoveOutDateTr IS NULL) 
OR (rentedHouseMoveInDateTr <= CURDATE() AND rentedHouseMoveOutDateTr > CURDATE()) 
于 2019-12-06T23:08:46.363 回答