16. Set Operation: INTERSECT
Beginner Mode
Objective
Retrieve the list of customers who meet both of the following criteria:
- They are new customers with a monthly spending greater than 1000.
- They are loyal customers with at least 3 years of membership and have a 'Premium' tier status.
Provide the customer_id and name of these customers, sorted in ascending order by customer_id.
Additional information
Tables Description:
The
NewCustomerstable:Column Type Description customer_id INTEGER Unique identifier for each customer name VARCHAR Name of the customer monthly_spend INTEGER Amount spent by the customer monthly join_date DATE Date when the customer joined The
LoyalCustomerstable:Column Type Description customer_id INTEGER Unique identifier for each customer name VARCHAR Name of the customer membership_years INTEGER Number of years the customer has been a member tier VARCHAR Membership tier of the customer (e.g., 'Premium') Constraints:
- Each customer appears only once in each table.
membership_yearsandmonthly_spendare positive integers.- The
tierfield contains single-word strings without special characters.
Output Requirements:
- The result should include only the
customer_idandnamecolumns. - The final output must be ordered by
customer_idin ascending order.
- The result should include only the
Examples
Example 1:
Output:
Input:
| LoyalCustomers | |||
|---|---|---|---|
| customer_id | membership_years | name | tier |
| 101 | 4 | Alice Smith | Premium |
| 103 | 3 | Carol White | Gold |
| 104 | 5 | David Brown | Premium |
| 105 | 3 | Eva Green | Premium |
| 106 | 4 | Frank Miller | Premium |
| NewCustomers | |||
|---|---|---|---|
| customer_id | join_date | monthly_spend | name |
| 101 | 2023-01-15 | 1200 | Alice Smith |
| 102 | 2023-02-20 | 800 | Bob Johnson |
| 103 | 2023-03-10 | 1500 | Carol White |
| 104 | 2023-04-05 | 2000 | David Brown |
| 105 | 2023-05-12 | 1800 | Eva Green |
| customer_id | name |
|---|---|
| 101 | Alice Smith |
| 104 | David Brown |
| 105 | Eva Green |
Code Environment
Sign in or try as guest to run your code.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
DoorDash
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
Meta
OpenAI
Hulu
Uber
X
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla