Summarize Rental Income per Landlord
Beginner Mode

Scenario

You work for a real estate company that manages properties for multiple landlords and need to summarize total rental income per landlord.

Task

Write a Snowflake SQL query that:

  1. Deduplicates {{ ref("properties_df") }} and {{ ref("landlords_df") }} (the input data may contain duplicate rows)
  2. Joins properties to landlords on landlord_id so that only landlords who own at least one property are included
  3. Concatenates first_name and last_name (separated by a space) into a column called landlord_name
  4. Calculates total_rental_income by summing the rent column per landlord
  5. Groups results by landlord_id and landlord_name

Schema

properties_df

Column Type Description
property_id Integer Unique property identifier
landlord_id Integer ID of the landlord who owns the property
property_type String Type of property (Apartment, Condo, House, etc.)
rent Float Monthly rent for the property
square_feet Integer Total square footage of the property
city String City where the property is located

landlords_df

Column Type Description
landlord_id Integer Unique landlord identifier
first_name String First name of the landlord
last_name String Last name of the landlord
email String Email address of the landlord
phone String Phone number of the landlord

Example

properties_df:

property_id landlord_id property_type rent square_feet city
1 101 Apartment 1500 1000 Seattle
2 101 Condo 1200 800 Seattle
3 102 House 2000 1500 Bellevue
4 103 Apartment 1800 1200 Redmond
5 103 Condo 1000 700 Redmond

landlords_df:

landlord_id first_name last_name email phone
101 John Smith [email protected] 555-123-4567
102 Jane Doe [email protected] 555-234-5678
103 Bob Johnson [email protected] 555-345-6789
104 Mary Williams [email protected] 555-456-7890
105 Jack Brown [email protected] 555-567-8901

Expected Output:

landlord_id landlord_name total_rental_income
101 John Smith 2700.0
102 Jane Doe 2000.0
103 Bob Johnson 2800.0

Note: Landlords 104 and 105 are excluded because they have no properties.

Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →