Magicsheet logo

Find Customers With Positive Revenue this Year

Easy
25%
Updated 8/1/2025

Asked by 1 Company

Topics

Find Customers With Positive Revenue this Year

What is this problem about?

The Find Customers With Positive Revenue this Year coding problem is a database task. You are given a Customers table with customer_id, year, and revenue. You need to return the IDs of all customers who had a revenue strictly greater than 0 in the year 2021.

Why is this asked in interviews?

Google uses this "Easy" question to verify basic SQL filtering skills. It tests whether you can use the WHERE clause to filter by multiple columns (both year and revenue). It’s a foundational query that reflects the type of day-to-day data retrieval tasks required in many software engineering roles.

Algorithmic pattern used

The SQL pattern is Conditional Selection. The query uses a standard SELECT statement with a WHERE clause containing two conditions joined by an AND operator.

Example explanation

Table Customers:

customer_idyearrevenue
1201850
1202130
22021-10
320210
  1. Row 1: Year is 2018. Ignore.
  2. Row 2: Year is 2021, Revenue is 30 (>0> 0). Match!
  3. Row 3: Year is 2021, Revenue is -10. No match.
  4. Row 4: Year is 2021, Revenue is 0. No match. Result: [1].

Common mistakes candidates make

  • Using OR instead of AND: Selecting anyone who was active in 2021 OR had positive revenue in any year.
  • Incorrect threshold: Checking for revenue >= 0 when the problem specifies "positive" (strictly >0> 0).
  • Hard-coding IDs: Not returning all matching IDs dynamically.

Interview preparation tip

When writing SQL, always look for the word "positive" vs "non-negative." It dictates whether you use > or >=. Precision in logical operators is a key trait of a good developer.

Similar Questions