Recyclable and Low Fat Products - Problem
๐ฑ Recyclable and Low Fat Products
You're working as a data analyst for a health-conscious grocery store chain that wants to promote environmentally friendly and healthy products. The store has a comprehensive database of all products with their nutritional and environmental attributes.
Given a Products table with the following structure:
| Column Name | Type |
|---|---|
| product_id | int |
| low_fats | enum ('Y', 'N') |
| recyclable | enum ('Y', 'N') |
Where:
product_idis the unique identifier for each productlow_fatsindicates if the product is low in fat ('Y' = Yes, 'N' = No)recyclableindicates if the product packaging is recyclable ('Y' = Yes, 'N' = No)
Your mission: Find all products that are both low fat and recyclable to feature in the store's new "Healthy & Green" promotion campaign.
Return the product IDs in any order.
Input & Output
Basic Example - Mixed Product Types
$
Input:
Products table:
+-------------+----------+------------+
| product_id | low_fats | recyclable |
+-------------+----------+------------+
| 0 | Y | N |
| 1 | Y | Y |
| 2 | N | Y |
| 3 | Y | Y |
| 4 | N | N |
+-------------+----------+------------+
โบ
Output:
+-------------+
| product_id |
+-------------+
| 1 |
| 3 |
+-------------+
๐ก Note:
Products 1 and 3 are the only ones that satisfy both conditions: low_fats = 'Y' AND recyclable = 'Y'. Product 0 is low fat but not recyclable, Product 2 is recyclable but not low fat, and Product 4 satisfies neither condition.
All Products Qualify
$
Input:
Products table:
+-------------+----------+------------+
| product_id | low_fats | recyclable |
+-------------+----------+------------+
| 10 | Y | Y |
| 20 | Y | Y |
| 30 | Y | Y |
+-------------+----------+------------+
โบ
Output:
+-------------+
| product_id |
+-------------+
| 10 |
| 20 |
| 30 |
+-------------+
๐ก Note:
All products in this healthy store satisfy both conditions, so all product IDs are returned.
No Products Qualify
$
Input:
Products table:
+-------------+----------+------------+
| product_id | low_fats | recyclable |
+-------------+----------+------------+
| 100 | N | N |
| 101 | Y | N |
| 102 | N | Y |
+-------------+----------+------------+
โบ
Output:
+-------------+
| product_id |
+-------------+
+-------------+
๐ก Note:
No products satisfy both conditions simultaneously. Product 101 is low fat but not recyclable, Product 102 is recyclable but not low fat, and Product 100 satisfies neither condition. The result is an empty set.
Constraints
- 1 โค Number of rows in Products table โค 1000
- product_id is unique for each row
- low_fats and recyclable are ENUM types with values ('Y', 'N')
- All ENUM values are guaranteed to be either 'Y' or 'N'
Visualization
Tap to expand
Understanding the Visualization
1
Products Enter Scanner
Each product passes through a dual-sensor scanner that checks both nutritional and environmental properties
2
Health Check
First sensor verifies if the product is low in fat (low_fats = 'Y')
3
Environmental Check
Second sensor verifies if the packaging is recyclable (recyclable = 'Y')
4
Decision Gate
Only products passing BOTH checks are directed to the 'Healthy & Green' collection bin
Key Takeaway
๐ฏ Key Insight: The AND operator in SQL acts like a quality gate that requires ALL conditions to be true simultaneously, making it perfect for multi-criteria filtering scenarios like this health and environmental compliance check.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code