OpenEnded
OpenEnded
Submitted by:
ID: 231014107
Section: 2
Submitted to:
Jannatul Ferdous Ruma
The Property Rental Platform is for storing, updating, deleting and retrieving information for
property rentals. The Entities with their attributes are-
Property: Id (PK), Address, Bedrooms, Bathrooms, SquareFeet, IsAvailable, OwnerId
(FK), PropertyManagerId (FK).
Owner: Id (PK), FirstName, LastName, Email, Phone.
Tenant: Id (PK), FirstName, LastName, Email, Phone.
LeaseAgreement: Id (PK), PropertyId (FK), TenantId (FK), StartDate, EndDate,
RentAmount
Payment: Id (PK), TeanatId (FK), LeaseAgreementId (FK), Date, Amount.
PropertyManager: Id (PK), FirstName, LastName, Email, Phone.
MaintenanceRequest: Id (PK), PropertyId (FK), TenantId (FK), Date, Issue,
IsResolved.
Entity Relationships:
Table Creation:
Create table Owner.
Explanation: The SQL query retrieves the "Address" and "Bedrooms" columns from the
"Property" table. But only for properties where the number of bedrooms is greater than 3. It
filters the data based on the condition "Bedrooms > 3," ensuring only properties with more than
3 bedrooms are selected.
2. Total rent amount of all lease agreements and the average square feet of all properties
Explanation: The SQL query calculates the total rent amount (RentAmount) by summing up all
values in the RentAmount column and finds the average square footage (SquareFeet) by
computing the average of all values in the SquareFeet column. It pulls data from two tables,
LeaseAgreement and Property.
Explanation: This SQL query selects the issue from the MaintenanceRequest table along with
the first and last names of tenants from the Tenant table. It joins both tables based on the
TenantId and Id fields and filters the results to only include unresolved maintenance requests
(where IsResolved is FALSE).
Explanation: This SQL query retrieves the first and last names of tenants along with the
payment date and amount by joining the Tenant and Payment tables on the TenantId. It filters the
results to include only payments made between January 1st 2024 and January 31st 2024.
5. List the first and last names of tenants who have signed lease agreements with a rent amount
greater than 15,000.
Explanation: This SQL query retrieves the first and last names of tenants whose IDs match
those listed in the LeaseAgreement table where the rent amount is greater than 15,000. It uses a
subquery to find TenantIds from LeaseAgreement with rent amounts above this threshold then
selects the corresponding tenants.
6. List all properties along with the tenant's first and last name
Explanation: This SQL query retrieves the address of properties along with the first and last
names of tenants. It joins the "Property" table with the "LeaseAgreement" table on the property
ID and then joins the "LeaseAgreement" table with the "Tenant" table on the tenant ID to get the
relevant data.
Explanation: This SQL query selects details from the "Property" table including the property
ID, address, bedrooms and owner ID. It also retrieves the owner's first and last names from the
"Owner" table using a LEFT JOIN ensuring all properties are shown even if they don't have an
associated owner.
8. Count the number of maintenance requests for each property
Explanation: This SQL query retrieves the address of each property and counts the number of
maintenance requests associated with each property. It joins the "Property" table with the
"MaintenanceRequest" table using the property ID then groups the results by property ID to get
the count of requests per property.
9. Find all properties that have tenants but are marked as unavailable
Explanation: This SQL query retrieves the address and availability status of properties that are
not available along with the first and last names of tenants associated with those properties. It
joins the "Property", "LeaseAgreement" and "Tenant" tables to connect property details with
tenant information filtering for unavailable properties.