SQL嵌套和/或语句

SQL嵌套和/或语句,sql,Sql,我被SQL语句卡住了。我正试图获得以下信息: Select fields from the rentedHouseTbl WHERE 属性与propertyIDTr匹配 **AND** the rentedHouseMoveInDateTr is less than or equal to today's date AND the rentedHouseMoveOutDateTr is NULL OR the rentedHouseMoveInDateT

我被SQL语句卡住了。我正试图获得以下信息:

Select fields from the rentedHouseTbl WHERE
属性与propertyIDTr匹配

**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()) )
SELECT*FROM rentedHouseTbl,其中propertyIDTr='1'和((rentedHouseMoveInDateTr
SELECT*FROM rentedHouseTbl
where(rentedhouse moveindatetr试试这个:

SELECT * FROM rentedHouseTbl 
where 
where propertyIDTr = '1'and
rentedHouseMoveInDateTr <= CURDATE() AND (rentedHouseMoveOutDateTr IS NULL or rentedHouseMoveOutDateTr > CURDATE())  
从RentedHouse TBL中选择*
哪里
其中propertyIDTr='1'和
RentedHouse MoveIndater CURDATE())
请尝试以下操作:

SELECT * FROM rentedHouseTbl 
  WHERE propertyIDTr = '1' 
     AND rentedHouseMoveInDateTr <= CURDATE() 
     AND ISNULL(rentedHouseMoveOutDateTr, DATE_ADD(CURDATE(), INTERVAL -1 DAY)) <> CURDATE()
从RentedHouse TBL中选择*
其中propertyIDTr='1'

rentedHouseMoveInDateTr谢谢!太棒了。它更短,实际上更有意义!我想我在php程序中而不是在mysql中测试了结果,结果更糟了,我的代码没有保存空值!我将使用它!
SELECT * FROM rentedHouseTbl 
  WHERE propertyIDTr = '1' 
     AND rentedHouseMoveInDateTr <= CURDATE() 
     AND ISNULL(rentedHouseMoveOutDateTr, DATE_ADD(CURDATE(), INTERVAL -1 DAY)) <> CURDATE()