내배캠(개인과제)/SQL

[라이브세션] 데이터와 친해지는 SQL 2회차

신짜린 2024. 6. 27. 18:50

문제 1

 group by 절을 사용하여, 서버별 게임캐릭터id수(중복값 허용x)와 평균 경험치를 추출해주세요.

select serverno
	, count(distinct game_actor_id)
	, avg(exp)
from users
group by serverno

 

문제 2

 group by 와 having 절을 사용하여, 날짜 별(yyyy-mm-dd) 게임캐릭터id수(중복값 허용x)를 구하고, 그 값이 10개를 초과하는 경우를 추출해주세요.

select date
	, count(distinct game_actor_id) ac_cnt
from users
group by date
having ac_cnt > 10

 

문제 3

 위와 같은 문제를 having 이 아닌 인라인 뷰 subquery 를 사용하여, 추출해주세요.

select date
	, cnt_id
from 
(
select date
	, count(distinct game_actor_id) cnt_id
from users
group by date
)a
where cnt_id > 10