[내일배움캠프 사전캠프]

[QAQC_2기] 사전캠프 퀘스트 마지막 문제

mulmoknnhama 2025. 4. 30. 17:56

이녀석 생각보다 양이 많다


마지막 문항

풀이 과정

번호. 풀이여부(정답/오답)

아래 컬럼은 정답컬럼

 

44. 풀었음(정답)

주문 id와 상품명 - 컬럼

둘이 공통된 것을 찾아야 하나 -> x -> left join

select o.id,
       p.name
from products p left join orders o on p.id=o.product_id

 

45. 못품

단어 바꿔치기로 독해를 잘해야한다. 연습치고는 장난이 좀 많이 들어간거 아니오..?

상품 id별로 총매출이 높은 상품 구하기 

특정값을 가져와야 하기 때문에 inner join

select p.id,
       sum(p.price*o.quantity) total_m
from products p inner join orders o on p.id=o.product_id
group by 1
order by total_m desc
limit 1

 

46.  풀었음, 값을 잘못넣음 (오답)

각 상품별 판매된 총수량 이길래, left join이 들어가는 줄 알았다.

select p.id,
       sum(quantity) sum_prdct
from products p inner join orders o on p.id=o.product_id
group by 1

 

47. 풀었음(오답)

주문된 모든 상품의 이름을 나열 -> left join 입력 - 오답

00의 모든 상품이면 특정조건이 성립되는 것 같다(inner join)

select p.name
from products p inner join orders o on p.id=o.product_id
where order_date = '2023-03-03'

 

48. 못풀었음(오답)

이것도 단어 바꿔치기로, 상품의 이름별로 가장많이 판매된 것을 구하면 된다.

특정조건 성립 inner join

select p.name,
       sum(o.quantity) sum_q
from products p inner join orders o on p.id=o.product_id
group by 1
order by sum_q desc
limit 1

 

49. 풀었음(정답)

~별로 - group by

평균 - avg()

특정조건 성립 inner join

select p.id,
       avg(o.quantity) avg_q
from products p inner join orders o on p.id=o.product_id
group by 1

 

50. 풀었음(정답과 오답 사이)

where절에 o.id 대신 o.quantity넣음

특정조건 성립 inner join 

select p.id,
       p.name
from products p inner join orders o on p.id=o.product_id
where o.id is null

 

퀘스트 끝!

 

느낀점

대충하면 계속 풀지 못하기 때문에 화가난다

복습을 좀 많이 해야겠다.