Coding Challenges/LeetCode

[SQL50] 1757. Recyclable and Low Fat Products

기록해연 2025. 2. 6. 11:02

난이도: EASY

 

문제

문제가 너무 쉬워서 5번 다시 읽음.

더보기

Table: Products

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| product_id  | int     |
| low_fats    | enum    |
| recyclable  | enum    |
+-------------+---------+

product_id is the primary key (column with unique values) for this table.
low_fats is an ENUM (category) of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
recyclable is an ENUM (category) of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not. 

Write a solution to find the ids of products that are both low fat and recyclable.
Return the result table in any order.
The result format is in the following example.

Example 1:

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           |
+-------------+

Explanation: Only products 1 and 3 are both low fat and recyclable.

 

나의 최종 제출 답안:

SELECT
    product_id
FROM Products
WHERE low_fats = 'Y'
AND recyclable = 'Y'

첫시도에 바로 통과.

'Coding Challenges > LeetCode' 카테고리의 다른 글

[SQL50] 595. Big Countries  (0) 2025.02.07
[SQL50] 584. Find Customer Referee  (1) 2025.02.07
[Java] 20. Valid Parentheses  (0) 2025.02.06
[Java] 14. Longest Common Prefix  (2) 2025.02.05
[Java] 13. Roman to Integer  (0) 2025.02.04