- 문제에 사용되는 table 구조
- table 칼럼 설명
구분
|
상세
|
schema
|
logid
|
로그id
|
int
|
ip_addr
|
ip주소
|
string
|
date
|
날짜, yyyy-mm-dd
|
string
|
game_account_id
|
게임계정id
|
string
|
game_actor_id
|
게임캐릭터id
|
int
|
level
|
현재레벨
|
int
|
exp
|
현재경험치
|
int
|
serverno
|
서버넘버
|
int
|
zone_id
|
지역넘버
|
int
|
etc_num1
|
파티id
|
int
|
etc_num2
|
파티원수
|
int
|
etc_str1
|
아이템 획득경로
|
string
|
etc_num3
|
아이템 획득량
|
int
|
etc_str2
|
아이템 이름
|
string
|
1. group by 절을 사용하여, 서버별 게임캐릭터id수(중복값 허용x)와 평균 경험치를 추출해주세요.
select serverno, count(distinct(game_actor_id)) count_id, avg(exp) avg_exp
from users
group by serverno
order by serverno

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

3. 위와 같은 문제를 having 이 아닌 인라인 뷰 subquery를 사용하여, 추출해주세요.
select a.date, a.count_id
from
(
select date, count(distinct(game_actor_id)) as count_id
from users
group by date
) a
where a.count_id > 10
2회차 숙제도 간단히 끝
'문제풀이 > 스파르타 - sql 문제' 카테고리의 다른 글
[SQL] 데이터와 친해지는 SQL | 3회차 숙제 (0) | 2024.06.28 |
---|---|
[SQL] 데이터와 친해지는 SQL | 1회차 숙제 (0) | 2024.06.26 |
[사전캠프] SQL 과제 | Lv3. 이용자의 포인트 조회하기 (0) | 2024.06.26 |
[사전캠프] SQL 과제 | Lv2. 날짜별 획득포인트 조회하기 (0) | 2024.06.26 |
[사전캠프] SQL 연습문제(7) (0) | 2024.06.26 |