Skip to content

Commit 199e358

Browse files
authored
Create 1757. Recyclable and Low Fat Products
2023.05.05 finished Runtime: 1127 ms, beats 32.45%
1 parent 11f32c6 commit 199e358

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Problem description:
3+
4+
+-------------+---------+
5+
| Column Name | Type |
6+
+-------------+---------+
7+
| product_id | int |
8+
| low_fats | enum |
9+
| recyclable | enum |
10+
+-------------+---------+
11+
product_id is the primary key for this table.
12+
low_fats is an ENUM of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
13+
recyclable is an ENUM of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
14+
15+
Write an SQL query to find the ids of products that are both low fat and recyclable.
16+
17+
Return the result table in any order.
18+
19+
The query result format is in the following example.
20+
*/
21+
22+
/*
23+
Example 1:
24+
25+
Input:
26+
Products table:
27+
+-------------+----------+------------+
28+
| product_id | low_fats | recyclable |
29+
+-------------+----------+------------+
30+
| 0 | Y | N |
31+
| 1 | Y | Y |
32+
| 2 | N | Y |
33+
| 3 | Y | Y |
34+
| 4 | N | N |
35+
+-------------+----------+------------+
36+
Output:
37+
+-------------+
38+
| product_id |
39+
+-------------+
40+
| 1 |
41+
| 3 |
42+
+-------------+
43+
Explanation: Only products 1 and 3 are both low fat and recyclable.
44+
*/
45+
46+
# Write your MySQL query statement below
47+
48+
SELECT product_id FROM Products WHERE low_fats = 'Y' AND recyclable = 'Y'

0 commit comments

Comments
 (0)