複数のテナントが存在するテナントがあり、一部のテナントには有効期限があります。残りのテナントはすべて同じテナントです。最新の有効期限を持つテナントを選択したい。最新の日付の属性のSQL選択列
これは私のコードです:
SELECT DISTINCT
property.scode AS "M nr",
tenant.scode AS "Contract nr",
unit.scode AS "Unit",
commamendments.DTSTART AS "Starting date",
sqft.DTDATE AS "Expiry date",
sqft.DSQFT0 AS "Area"
FROM
property
LEFT JOIN unit ON unit.hproperty = property.hmy
LEFT JOIN unitxref ON unitxref.hunit = unit.hmy
LEFT JOIN commamendments ON commamendments.hmy = unitxref.hamendment
LEFT JOIN tenant ON tenant.hmyperson = commamendments.htenant
JOIN attributes ON attributes.HPROP = property.hmy
JOIN sqft ON sqft.hpointer = unit.hmy
WHERE property.scode = '481'
AND sqft.DSQFT0 != '0'
AND ('9/30/2017 12:00:00 AM' BETWEEN commamendments.DTSTART AND commamendments.DTEND)
ORDER BY commamendments.DTEND`
私は今受け取る何
Mnr Contract nr Unit Starting date Expiry date Area
481 1 1 9-10-2017 12-31-2018 400
481 2 2 8-10-2017 12-31-2019 500
.....
とテーブルがあるしたい出力として:
Mnr Contract nr Unit Starting date Expiry date Area
481 1 1 9-10-2017 12-31-2018 400
481 1 1 9-10-2017 09-20-2018 400
481 2 2 8-10-2017 12-31-2019 500
481 2 2 8-10-2017 1-31-2018 500
.....
既に試行したクエリを提供できますか? –
Alwayタグur DBMS。 https://stackoverflow.com/help/how-to-ask – Laxmi
あなたの質問に詳細を追加してください。 – RAS