문제 1:
Recyclable and Low Fat Products
문제 설명:
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.
product_id는 이 테이블의 기본 키(고유한 값을 갖는 열)입니다.
low_fats is an ENUM (category) of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
low_fats는 ('Y', 'N') 유형의 ENUM(카테고리)입니다. 여기서 'Y'는 이 제품이 저지방임을 의미하고 'N'은 그렇지 않음을 의미합니다.
recyclable is an ENUM (category) of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
재활용 가능은 ('Y', 'N') 유형의 ENUM(범주)입니다. 여기서 'Y'는 이 제품이 재활용 가능함을 의미하고 'N'은 재활용 가능하지 않음을 의미합니다.
Write a solution to find the ids of products that are both low fat and recyclable.
저지방이면서 재활용이 가능한 제품의 ID를 찾는 솔루션을 작성하세요.
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 |
+-------------+
코드 :
select product_id
from products
where low_fats = 'Y'
and recyclable = 'Y'
문제 2:
Find Customer Referee
문제 설명:
Table: Customer
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| referee_id | int |
+-------------+---------+
In SQL, id is the primary key column for this table.
SQL에서 id는 이 테이블의 기본 키 열입니다.
Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them.
이 표의 각 행은 고객의 ID, 이름, 그리고 해당 고객을 추천한 고객의 ID를 나타냅니다.
Find the names of the customer that are not referred by the customer with id = 2.
고객이 추천하지 않은 고객의 이름을 찾으세요 id = 2.
Return the result table in any order.
결과 표를 임의의 순서 로 반환합니다 .
The result format is in the following example.
결과 형식은 다음 예와 같습니다.
출력 예시 :
Example 1:
Input:
Customer table:
+----+------+------------+
| id | name | referee_id |
+----+------+------------+
| 1 | Will | null |
| 2 | Jane | null |
| 3 | Alex | 2 |
| 4 | Bill | null |
| 5 | Zack | 1 |
| 6 | Mark | 2 |
+----+------+------------+
Output:
+------+
| name |
+------+
| Will |
| Jane |
| Bill |
| Zack |
+------+
코드:
select name
from customer
where referee_id != 2
or referee_id is null
order by id
문제 3:
Big Countries
문제 설명:
Table: World
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| name | varchar |
| continent | varchar |
| area | int |
| population | int |
| gdp | bigint |
+-------------+---------+
name is the primary key (column with unique values) for this table.
name은 이 테이블의 기본 키(고유한 값이 있는 열)입니다.
Each row of this table gives information about the name of a country, the continent to which it belongs, its area, the population, and its GDP value.
이 테이블의 각 행은 국가 이름, 속한 대륙, 면적, 인구 및 GDP 값에 대한 정보를 제공합니다.
A country is big if:
나라가 크다는 것은:
it has an area of at least three million (i.e., 3000000 km2), or
면적이 최소 300만(3000000 km2) 이상인 경우
it has a population of at least twenty-five million (i.e., 25000000).
인구는 적어도 2,500만명입니다.(25000000)
Write a solution to find the name, population, and area of the big countries.
큰 나라 의 이름, 인구, 면적을 찾는 솔루션을 작성하세요.
Return the result table in any order.
결과 표를 임의의 순서 로 반환합니다 .
The result format is in the following example.
결과 형식은 다음 예와 같습니다.
출력 예시:
Example 1:
Input:
World table:
+-------------+-----------+---------+------------+--------------+
| name | continent | area | population | gdp |
+-------------+-----------+---------+------------+--------------+
| Afghanistan | Asia | 652230 | 25500100 | 20343000000 |
| Albania | Europe | 28748 | 2831741 | 12960000000 |
| Algeria | Africa | 2381741 | 37100000 | 188681000000 |
| Andorra | Europe | 468 | 78115 | 3712000000 |
| Angola | Africa | 1246700 | 20609294 | 100990000000 |
+-------------+-----------+---------+------------+--------------+
Output:
+-------------+------------+---------+
| name | population | area |
+-------------+------------+---------+
| Afghanistan | 25500100 | 652230 |
| Algeria | 37100000 | 2381741 |
+-------------+------------+---------+
코드 :
select name,
population,
area
from world
where area >= 3000000
or population >= 25000000
'SQL(진짜 가끔 올라옴)' 카테고리의 다른 글
SQL 문제(LeetCode) 09.23 (2) | 2024.09.23 |
---|---|
SQL 문제 (LeetCode) 09.20 (0) | 2024.09.20 |
RDBMS 관계형 데이터베이스 (1) | 2024.08.29 |
NoSQL 비관계형 데이터베이스 간단 (1) | 2024.08.28 |
SQL 문법 정리(진행중) (0) | 2024.07.19 |