1757 Recyclable and Low-Fat Products
Problem Statement
Table Products
product_id
int
low_fats
enum
recyclable
enum
product_id
is the primary key (column with unique values) for this table.low_fats
is anENUM
(category) of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.recyclable
is anENUM
(category) of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
Instructions
Write an SQL query to find the
product_id
of the products that are both low fat and recyclable.Return the result table in any order.
The query result format is in the following example.
For the whole problem statement, please refer here.
Plans
We need to find the
product_id
of the products that are both low fat and recyclable.We can achieve this by filtering the rows in the
Products
table wherelow_fats = 'Y'
andrecyclable = 'Y'
.We will use the
SELECT
statement to retrieve theproduct_id
column from theProducts
table.We will use the
WHERE
clause to filter the rows wherelow_fats = 'Y'
andrecyclable = 'Y
.Finally, we will return the
product_id
of the products that are both low fat and recyclable.
Solution
Explanation
SELECT product_id
:This part of the query specifies that we want to retrieve the
product_id
column from the table. Theproduct_id
uniquely identifies each product in theProducts
table.
FROM Products
:This specifies the table from which we are selecting the data. In this case, the table is named
Products
.
WHERE low_fats = 'Y' AND recyclable = 'Y'
:This is the condition that filters the rows in the
Products
table.low_fats = 'Y'
checks if the product is low fat.recyclable = 'Y'
checks if the product is recyclable.The
AND
operator ensures that only the products that meet both conditions (low fat and recyclable) are selected.
Last updated