일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 표준편차
- 자연어 논문 리뷰
- torch
- 짝수
- HackerRank
- LSTM
- 설명의무
- 자연어 논문
- nlp논문
- SQL 날짜 데이터
- 카이제곱분포
- 코딩테스트
- GRU
- 그룹바이
- update
- sigmoid
- 서브쿼리
- NLP
- MySQL
- Statistics
- 논문리뷰
- leetcode
- 자연어처리
- sql
- SQL코테
- airflow
- Window Function
- inner join
- CASE
- t분포
- Today
- Total
HAZEL
[SQL : Leetcode] 595. Big Countries / 620. Not Boring Movies : 짝수, 홀수 본문
[SQL : Leetcode] 595. Big Countries / 620. Not Boring Movies : 짝수, 홀수
Rmsid01 2021. 2. 23. 21:511] 595. Big Countries
>> 문제
There is a table World
+-----------------+------------+------------+--------------+---------------+
| name | continent | area | population | gdp |
+-----------------+------------+------------+--------------+---------------+
| Afghanistan | Asia | 652230 | 25500100 | 20343000 |
| Albania | Europe | 28748 | 2831741 | 12960000 |
| Algeria | Africa | 2381741 | 37100000 | 188681000 |
| Andorra | Europe | 468 | 78115 | 3712000 |
| Angola | Africa | 1246700 | 20609294 | 100990000 |
+-----------------+------------+------------+--------------+---------------+
A country is big if it has an area of bigger than 3 million square km or a population of more than 25 million.
Write a SQL solution to output big countries' name, population and area.
For example, according to the above table, we should output:
+--------------+-------------+--------------+
| name | population | area |
+--------------+-------------+--------------+
| Afghanistan | 25500100 | 652230 |
| Algeria | 37100000 | 2381741 |
+--------------+-------------+--------------+
>> 문제 해결 코드
Select name, population, area
from World
where ( area > 3000000 ) or ( population > 25000000 )
※ where 절을 두개로 묶는 것
Leetcode 595. Big Countries: https://leetcode.com/problems/big-countries/
2] 620. Not Boring Movies
>> 문제
X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a poster indicating the movies’ ratings and descriptions.
Please write a SQL query to output movies with an odd numbered ID and a description that is not 'boring'. Order the result by rating.
For example, table cinema:
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 1 | War | great 3D | 8.9 |
| 2 | Science | fiction | 8.5 |
| 3 | irish | boring | 6.2 |
| 4 | Ice song | Fantacy | 8.6 |
| 5 | House card| Interesting| 9.1 |
+---------+-----------+--------------+-----------+
For the example above, the output should be:
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 5 | House card| Interesting| 9.1 |
| 1 | War | great 3D | 8.9 |
+---------+-----------+--------------+-----------+
>> 문제 해결 코드
select id , movie, description, rating
from cinema
where description != 'boring' and mod(id,2) = 1
order by rating desc
※ 짝수, 홀수 번호만 불러오는 방법
: where MOD( ID, 2 ) = 0 : 짝수 / where MOD( ID, 2 ) = 1 : 홀수
Leetcode 620. Not Boring Movies: https://leetcode.com/problems/not-boring-movies/
'DATA ANALYSIS > SQL' 카테고리의 다른 글
[SQL : HackerRank] Japan Population / Weather Observation Station 2 / Weather Observation Station 18 (0) | 2021.02.25 |
---|---|
[SQL : Leetcode] 182. Duplicate Emails / 175. Combine Two Tables (0) | 2021.02.24 |
[SQL : HackerRank] UNION (0) | 2021.02.14 |
[SQL : HackerRank/Leetcode] SELF JOIN (0) | 2021.02.13 |
[SQL : Leetcode] LEFT JOIN 문 (0) | 2021.02.13 |