OkBublewrap

2025-01-07 TIL (A/B Test, SQL CodeKata) 본문

Today I Learning

2025-01-07 TIL (A/B Test, SQL CodeKata)

옥뽁뽁 2025. 1. 7. 20:00

아티클 # 16

 

A/B 테스트 제대로 이해하기: ①테스트를 설계할 때 우리의 진짜 질문은? | 요즘IT

서비스 기획, PM, 그리고 그로스 해킹과 관련한 부트캠프나 신입 교육 과정을 살펴보면, A/B 테스트에 관한 이야기가 많다. 아마도 서비스를 개선하는 실험 방안 중 하나로 A/B 테스트가 가장 유명(

yozm.wishket.com

 

1. 아티클 주요 내용 요약

  • 핵심 주제: A/B 테스트를 설계할 때 우리의 진짜 질문은?
  • 주요 내용:
    • 우리는 암묵적으로 A/B 방안의 결과가 상당히 크길 바란다.
    • 우리는 실험의 진행이 공정하길 바란다.
    • 우리는 이번 실험의 결과가 이례적이거나 우연이 아니길 바란다.
  • A/B 테스트의 진짜 질문
    • 우리가 궁금한 질문에 관한 답을 얻기 위해 A/B 테스트의 설계와 결과 해석을 주요내용으로 단순하게 정의할 수 없다.

 

 


 

HackerRank Interviews

 

Interviews | HackerRank

find total number of view, total number of unique views, total number of submissions and total number of accepted submissions.

www.hackerrank.com

 

1. 문제 설명

1. 출력  contest_id, hacker_id, name, total_submissions, total_accepted_submissions, total_views, total_unique_views의 합계

2. 네 개의 합계가 모두 0인 경우 결과에서 콘테스트를 제외

 

2.예제

Contests

contest_id hacker_id name
66406 17973 Rose
66556 79153 Angela
94828 80275 Frank

 

Colleges

college_id contest_id
11219 66406
32473 66556
56685 94828

 

Challenges

challenge_id college_id
18765 11219
47127 11219
60292 32473
72974 56685

 

View_Stats

challenge_id total_views total_unique_views
47127 26 19
47127 15 14
18765 43 10
18765 72 13
75516 35 17
60292 11 10
72974 41 15
75516 75 11

 

Submission_Stats

challenge_id total_submissions total_accepted_submissions
75516 34 12
47127 27 10
47127 56 18
75516 74 12
75516 83 8
72974 68 24
72974 82 14
47127 28 11

 

Sample Output

66406 17973 Rose 111 39 156 56
66556 79153 Angela 0 0 11 10
94828 80275 Frank 150 38 41 15

 

Explanation

contest  66406 는 college 11219에서 진행된다. 

college 11219에서는 challenge 18765, 47127에서 진행이 된다.

계산하면 다음과 같다.

 

contest 66406

total_subissions 총합 27 + 56 + 28 = 111

total_accepted_submissions 총합 10 + 18 + 11 = 39

total_views 총합 26 + 15 + 43 + 72 = 156

total_unique_views 총합 10 + 13 + 14 + 19

 

3. 풀이

Contest : Collenge = 1: 1 

Colleges : Challenges = 1 : M

Challenges : View_Stats = 1 : M

Challenges : Submission_Stats 1 : M

 

1. View_Stats, Challenges Table을 Challenge_id을 기준으로 합계

-- View_Stats
(
    select challenge_id
        , sum(total_views) as total_views
        , sum(total_unique_views) as total_unique_views
    from View_Stats 
    group by challenge_id
)
        
-- Submission_Stats
(
select challenge_id
        , sum(total_submissions) as total_submissions
        , sum(total_accepted_submissions) as total_accepted_submissions
from Submission_Stats
group by challenge_id
)

 

2.  Challenge_id을 이어줄 Table 생성

from Contests c1
    join Colleges c2 on c1.contest_id = c2.contest_id
    join Challenges c3 on c2.college_id = c3.college_id
    left join 
        (
            select challenge_id
                , sum(total_views) as total_views
                , sum(total_unique_views) as total_unique_views
            from View_Stats 
            group by challenge_id
        ) v on c3.challenge_id = v.challenge_id
    left join 
        (
        select challenge_id
                , sum(total_submissions) as total_submissions
                , sum(total_accepted_submissions) as total_accepted_submissions
        from Submission_Stats
        group by challenge_id
        ) s on c3.challenge_id = s.challenge_id

 

 

3. Contests Table 기준으로 그룹화 & 정렬

select c1.contest_id, 
    c1.hacker_id, 
    c1.name, 
    sum(s.total_submissions), 
    sum(s.total_accepted_submissions), 
    sum(v.total_views), 
    sum(v.total_unique_views)
from Contests c1
    join Colleges c2 on c1.contest_id = c2.contest_id
    join Challenges c3 on c2.college_id = c3.college_id
    left join 
        (
            select challenge_id
                , sum(total_views) as total_views
                , sum(total_unique_views) as total_unique_views
            from View_Stats 
            group by challenge_id
        ) v on c3.challenge_id = v.challenge_id
    left join 
        (
        select challenge_id
                , sum(total_submissions) as total_submissions
                , sum(total_accepted_submissions) as total_accepted_submissions
        from Submission_Stats
        group by challenge_id
        ) s on c3.challenge_id = s.challenge_id
group by c1.contest_id, c1.hacker_id, c1.name
having 
    (SUM(s.total_submissions) +
     SUM(s.total_accepted_submissions) +
     SUM(v.total_views) +
     SUM(v.total_unique_views)) > 0
order by c1.contest_id

 

'Today I Learning' 카테고리의 다른 글

2025-01-09 TIL (SQL codekata, Sub Query)  (0) 2025.01.09
2025-01-08 TIL (A/B Test, 통계분포)  (0) 2025.01.08
2025-01-06 TIL (가설 검증 방법)  (0) 2025.01.06
WIL -6주차  (0) 2025.01.04
2025-01-03 TIL (김오기 기초프로젝트)  (0) 2025.01.03