Similar Problems

Similar Problems not available

Find Customers With Positive Revenue This Year - Leetcode Solution

Companies:

LeetCode:  Find Customers With Positive Revenue This Year Leetcode Solution

Difficulty: Easy

Topics: database  

Problem statement:

Given a table "Customers" with columns "id", "name" and "revenue" for each customer, return the list of customers with positive revenue this year. Assume the year is 2021.

Solution:

We can solve this problem using a simple SQL query. We need to select the "name" column from the "Customers" table where the "revenue" column is greater than zero and contains a date in the year 2021.

The SQL query becomes:

SELECT name
FROM Customers
WHERE revenue > 0 AND year(date) = 2021;

Explanation:

In the query, we are using the "SELECT" keyword to select the "name" column. We are using the "FROM" keyword to specify the table "Customers".

Next, we are using the "WHERE" keyword to filter the data. We are selecting only those rows where the "revenue" column is greater than zero and where the date column contains a date from the year 2021.

We are using the "year" function to extract the year from the date column.

Finally, we are executing the SQL query to get the desired output.

This query will return all the customers with a positive revenue in 2021.

Find Customers With Positive Revenue This Year Solution Code

1