lettings · v1 · Head of Lettings
1,959 leases
Lease running at now, ending between now and now + window_days, tenant not moved out.
From renewal_window (lettings) · tables renewal_offers, leases
SQL and the first rows of 1959
SELECT l.id AS lease_id, l.building_id, l.end_date, l.monthly_rent,
(SELECT max(o.status) FROM renewal_offers o WHERE o.lease_id = l.id AND o.sent_at <= TIMESTAMP '2026-11-02 20:00:00') AS offer_status,
l.notice_given_at IS NOT NULL AND l.notice_given_at <= TIMESTAMP '2026-11-02 20:00:00' AS tenant_leaving
FROM leases l
WHERE l.start_date <= TIMESTAMP '2026-11-02 20:00:00' AND l.end_date + INTERVAL 1 DAY > TIMESTAMP '2026-11-02 20:00:00'
AND l.end_date <= TIMESTAMP '2026-11-02 20:00:00' + INTERVAL (90) DAY
AND (l.moved_out_at IS NULL OR l.moved_out_at > TIMESTAMP '2026-11-02 20:00:00')
ORDER BY l.end_date, l.id
[
{
"building_id": 1,
"end_date": "2026-11-30 00:00:00",
"lease_id": 11,
"monthly_rent": 1225.0,
"offer_status": "declined",
"tenant_leaving": true
},
{
"building_id": 1,
"end_date": "2026-11-30 00:00:00",
"lease_id": 44,
"monthly_rent": 720.0,
"offer_status": "accepted",
"tenant_leaving": false
},
{
"building_id": 1,
"end_date": "2026-11-30 00:00:00",
"lease_id": 60,
"monthly_rent": 1875.0,
"offer_status": "declined",
"tenant_leaving": true
},
{
"building_id": 2,
"end_date": "2026-11-30 00:00:00",
"lease_id": 67,
"monthly_rent": 1925.0,
"offer_status": "accepted",
"tenant_leaving": false
},
{
"building_id": 2,
"end_date": "2026-11-30 00:00:00",
"lease_id": 86,
"monthly_rent": 1150.0,
"offer_status": "accepted",
"tenant_leaving": false
},
{
"building_id": 2,
"end_date": "2026-11-30 00:00:00",
"lease_id": 98,
"monthly_rent": 515.0,
"offer_status": "declined",
"tenant_leaving": true
},
{
"building_id": 2,
"end_date": "2026-11-30 00:00:00",
"lease_id": 125,
"monthly_rent": 1540.0,
"offer_status": "accepted",
"tenant_leaving": false
},
{
"building_id": 3,
"end_date": "2026-11-30 00:00:00",
"lease_id": 128,
"monthly_rent": 1000.0,
"offer_status": "declined",
"tenant_leaving": true
}
]