https://school.programmers.co.kr/learn/courses/30/lessons/131532
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
매우 단순한 조인문제
두 테이블 조인 후, gender 가 null 이 아닌, user_id 를 distinct 로 중복 제거해서 카운트
select year(o.sales_date), month(o.sales_date) as month,u.gender as gender, count(distinct u.user_id) as users
from user_info as u inner join online_sale as o
on u.user_id = o.user_id and u.gender is not null
group by year(o.sales_date), month(o.sales_date), u.gender
order by year(o.sales_date), month(o.sales_date), u.gender
'코딩테스트 > 문제풀이' 카테고리의 다른 글
[프로그래머스] 자동차 대여 기록 별 대여 금액 구하기 SQL (0) | 2023.10.03 |
---|---|
[프로그래머스] 입양 시각 구하기(2) SQL (1) | 2023.10.02 |
[프로그래머스] 우유와 요거트가 담긴 장바구니 SQL (0) | 2023.09.26 |
[프로그래머스] 자동차 평균 대여 기간 구하기 SQL (0) | 2023.09.26 |
[프로그래머스] 상품을 구매한 회원 비율 구하기 SQL (0) | 2023.09.26 |