일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 자연어처리
- Statistics
- CASE
- LSTM
- MySQL
- SQL 날짜 데이터
- 짝수
- 표준편차
- 설명의무
- 논문리뷰
- sigmoid
- 서브쿼리
- torch
- airflow
- 그룹바이
- nlp논문
- 자연어 논문
- 카이제곱분포
- leetcode
- t분포
- inner join
- NLP
- update
- HackerRank
- Window Function
- 자연어 논문 리뷰
- 코딩테스트
- SQL코테
- GRU
- sql
- Today
- Total
HAZEL
[SQL : Leetcode] 182. Duplicate Emails / 175. Combine Two Tables 본문
[SQL : Leetcode] 182. Duplicate Emails / 175. Combine Two Tables
Rmsid01 2021. 2. 24. 11:571] 182. Duplicate Emails
>> 문제
Write a SQL query to find all duplicate emails in a table named Person.
+----+---------+
| Id | Email |
+----+---------+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+----+---------+
For example, your query should return the following for the above table:
+---------+
| Email |
+---------+
| a@b.com |
+---------+
>> 문제 해결 코드
select Email
from person
group by Email
having count(*) >= 2
※ 중복된 email을 구하는 방법으로 그룹바이의 count를 세서 2이상인것을 구했다.
https://leetcode.com/problems/duplicate-emails/
Duplicate Emails - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
2] 175. Combine Two Tables
>> 문제
Table: Person
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
PersonId is the primary key column for this table.
Table: Address
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
AddressId is the primary key column for this table.
Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:
FirstName, LastName, City, State
>> 문제 해결 코드
select FirstName, LastName, City, State
from person
left join Address on person.PersonId = Address.PersonId
※ 해결 결과로만 보면, 엄청 간단하다. 그러나 left join 을 써야지 ! 라는 생각이 들려면, 테이블 정의 뿐만 아니라, 어떻게 생겼는지 select를 해보고 출력해야하는 과정이 있어야 했다.
-> 문제를 풀때, 어떤 방식으로 문제에 접근할지 생각하는 것이 중요한 것 같다.
https://leetcode.com/problems/combine-two-tables/
Combine Two Tables - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
'DATA ANALYSIS > SQL' 카테고리의 다른 글
[SQL : select 서브쿼리, join ] HackerRank : New Companies (0) | 2021.02.26 |
---|---|
[SQL : HackerRank] Japan Population / Weather Observation Station 2 / Weather Observation Station 18 (0) | 2021.02.25 |
[SQL : Leetcode] 595. Big Countries / 620. Not Boring Movies : 짝수, 홀수 (0) | 2021.02.23 |
[SQL : HackerRank] UNION (0) | 2021.02.14 |
[SQL : HackerRank/Leetcode] SELF JOIN (0) | 2021.02.13 |