728x90

https://leetcode.com/problems/swap-salary/

 

Swap Salary - 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

[problem]

성별 f,m 인경우 전체 바꿔버리기

[analysis]

1. update이용해서 데이터 업뎃

-> UPDATE 테이블이름

SET 필드이름1=데이터값1, 필드이름2=데이터값2, ...

WHERE 필드이름=데이터값

 

2.. case when 이용해서 f인 경우, m인 경우 분리

-> case when 문법 : CASE WHEN 조건절 THEN 참일때 값 ELSE 거짓일 때 값 END 컬럼명

 

[solution]

728x90
728x90

https://leetcode.com/problems/customer-placing-the-largest-number-of-orders/

 

[problem]

 order_number가 가장 많은 customer 출력

[anlysis]

1. order no 가장많은 =  select top 1이용

2. count(*) 

select 변수 order by count(*)를 통해 행의 개수를 출력할 수 있다

 

[solution]

728x90
728x90

https://leetcode.com/problems/game-play-analysis-i/

 

[problem]

[analysis]

1. eventdate가 여러 데이터가 있으므로 min을 이용

2. id group by

 

[solution]

728x90
728x90

https://leetcode.com/problems/customers-who-never-order/

 

Customers Who Never Order - 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

[problem]

Write an SQL query to report all customers who never order anything.

Return the result table in any order.

 

[analysis]

1. 두 테이블 left join

2. cutomnerID가 null인 경우 where을 사용해서 리스트 출력해야함

join 과 where은 같이 사용할 수 있따!!

 

[soultion]

728x90
728x90

https://leetcode.com/problems/not-boring-movies/

 

Not Boring Movies - 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

 

[problem]

1. 홀수인경우

2. description 에 boring이 들어간 경우 제외

3. order by DESC 적용

[analysis]

1.where 절을 통한 조건 적용

--> 홀수인경우 id % 2 !=0 으로 나타낼 수 있음 / boring문자 제외도 !를 이용함

[solution]

728x90
728x90

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

 

[problem]

두 테이블간의 join 필요

Write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead.

Return the result table in any order.

[analysis]

1. address가 null인 경우도 정보를 보여줘야 하므로 person table 기준으로 left join 실행

2. 두 테이블에 공통 컬럼인 personId 기준으로 join

 

[solution]

728x90
728x90

https://leetcode.com/problems/duplicate-emails/submissions/

 

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

 

[problem]

email데이터 중복없이 정보 출력하기

[analysis]

1. 중복된 이메일 제외 위해서 email로 group by 해줌

2. having count email >1 (2이상이면 중복임)

* having은 group by에서 연산한 결과물에 조건을 줄 때 사용 where과는 다르다.

 

[solution]

728x90

+ Recent posts