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

[QAQC_2기] 사전캠프 퀘스트 1 ~ 4 문항

mulmoknnhama 2025. 4. 29. 17:41

Google form 말고도 사전캠프 퀘스트 풀이를 작성한다.

 

SQL 구문을 배웠으니 써먹어 볼 시간이다!


제 1 문항

풀이과정

 

1. 필요한 컬럼 - name, position

컬럼에서 name 과 position 만 필요로 하기 때문에, 그것만 작성한다

select name,
       position
from sparta_employees

 

2. 필요한 컬럼 - 직급(position)

하지만, 중복없는 값을 원하기 때문에 count에서 배웠던 distinct 를 적용한다

select distinct position
from sparta_employees

 

3. 필요한 컬럼 - 전체

연봉 40,000~60,000 사이의 직원을 선택하는 것이니 where절을 적용, 비교연산 [between-and-]

select *
from sparta_employees
where salary between 40000 and 60000

 

4. 필요한 컬럼 - 전체

입사일 23년 1월 1일 이전을 선택 - where절, 비교연산 [<]

select *
from sparta_employees
where hire_date < '2023-01-01'

 

컬럼명에 보라색이 왜 씌워진지는 모르겠는데, 오류...?

 

난이도 (상 / 상중 / / 중하 / 하)

count 배우기 이전에 2번 풀기가 어려웠는데, 알고나니 수월해진 것 같다


제 2 문항

풀이과정

 

5. 필요한 컬럼 - 제품 이름(product_name), 가격(price)

select product_name,
       name
from products

 

6. 필요한 컬럼 - 전체

제품이름에 '프로' 가 해당하는 제품 선택 - where절, like 에 '%프로%' 적용

select *
from products
where product_name like '%프로%'

 

7. 필요한 컬럼 - 전체

위 문제랑 거의 똑같다. 하지만, 갤로 시작하는 이름이기에 like절에 '갤%'

select *
from products
where product_name like '갤%'

 

8. 필요한 컬럼 - 가격

모든 제품을 구매하기 위해 필요한 돈이 필요하다고 하는데, 가격의 합계가 필요 - sum함수를 이용

합계 컬럼에 별명을 지칭하기 위해 total_price 작성

select sum(price) total_price
from products

 

 

난이도 (상 / 상중 / 중 / 중하 / 하)

1문항 보다 다소 괜찮다


제 3 문항

풀이 과정

 

9. 필요한 컬럼 - 고객 이름(customer_id)

2개 이상의 수량 - where절, 비교연산[>], 조건컬럼(amount)

select customer_id
from orders
where amount > 1

 

10. 필요한 컬럼 - 전체

23년 1월 1일 이후의 주문일과 2개 이상의 수량 - where절, 비교연산[>,>=], 조건컬럼(order_date, amount)

select *
from orders
where order_date > '2023-11-02' and amount >= 2

 

11. 필요한 컬럼 - 전체

3개 미만이면서, 운송비가 15,000 초과 - where절, 비교연산, 조건컬럼(amount, shipping_fee)

select *
from orders
where amount < 3 and shipping_fee > 15000

 

12. 필요한 컬럼 - 전체

운송비를 내림차순으로 정리 - order by절 과 오름차순에 반대에 해당하는 desc를 넣는다

select *
from orders
order by shipping_fee desc

 

난이도 (상 / 상중 / 중 / 중하 / 하)

그래도 잘 읽어보지 않으면 틀린 값이 나온다. 조심하자!


제 4 문항

풀이 과정

select name, track from sparta_students
select * from sparta_students where. track is not 'Unity'
select * from sparta_students where enrollment_year in(2021, 2023)
select enrollment_year from sparta_students where track='Nord.js' and grade='A'

13. 필요한 컬럼 - 이름(name)과 트랙(track)

select name,
       track
from sparta_students

 

14. 필요한 컬럼 - 전체

Unity 트랙이 아닌 학생을 선택 - where 절, [<>]

select *
from sparta_students
where track is not 'Unity'

 

15. 필요한 컬럼 - 전체

입학년도 21년과 23년을 선택 - where절, 같은 컬럼에 떨어저 있는 데이터를 포함하는 in()

select *
from sparta_students
where enrollment_year in(2021, 2023)

 

16. 필요한 컬럼 - 입학년도

Nord.js트랙과 A학점을 조건 - where절, and

select enrollment_year
from sparta_students
where track='Nord.js' and grade='A'

 

이 문항에서는 15번 where절에 and로 넣었는데, 답안을 보니 틀렸었다.

in구문이 있었다는 걸 깜빡.. 하하

 

난이도 (상 / 상중 /  / 중하 / 하)

만점은 아니지만 다시 점검하는 과정이니 오히려 좋다.


5문항까지 집어넣으려고 했으나, 풀이가 막힌게 있어서 분리한다