我需要獲得所有Room_IDs
,其中Status
報告爲空,然後僅在以後的日期佔用。TSQL:條件組查詢
這是我使用作爲實例的簡化表:
**Room_Id Status Inspection_Date**
1 vacant 5/15/2015
2 occupied 5/21/2015
2 vacant 1/19/2016
1 occupied 12/16/2015
4 vacant 3/25/2016
3 vacant 8/27/2015
1 vacant 4/17/2016
3 vacant 12/12/2015
3 occupied 3/22/2016
4 vacant 2/2/2015
4 vacant 3/24/2015
我的結果應該是這樣的:
**Room_Id Status Inspection_Date**
1 vacant 5/15/2015
1 occupied 12/16/2015
1 vacant 4/17/2016
3 vacant 8/27/2015
3 vacant 12/12/2015
3 occupied 3/22/2016