Search

join 활용

문제:
아래 조건을 만족하여, 알맞은 조인방식으로 users 테이블과 payment 테이블을 조인해주세요. case when 구문을 사용하여 결제를 한 게임계정과 결제를 하지 않은 게임계정을 구분해주시고, 컬럼이름을 gb로 지정해주세요. gb를 기준으로 게임계정수를 중복값없이 추출해주세요. 컬럼 이름은 usercnt로 지정해주세요.조건1) payment 테이블에 게임계정이 있으면 결제한 고객으로 생각해주세요.힌트: 기준이 되는 테이블의 데이터는 그대로 두어야겠죠?
박지완 select c.gb, count(1) as usercnt from(select case when id_cnt is null then '결제안함' else '결제함' end gb from( select distinct game_account_id from users )a left join ( select game_account_id,1 as id_cnt from payment group by game_account_id )b on a.game_account_id=b.game_account_id )c group by c.gb
SQL
복사
배시환 select case when p.game_account_id is not null then "결제 함" else "결제 안함" end as gb, count(distinct(u.game_account_id )) as usercnt from users u left join payment p on u.game_account_id = p.game_account_id group by gb
SQL
복사
이하진 select case when pay_amount is null then '결제안함' else '결제함' end gb, count(distinct u.game_account_id) usercnt from basic.users u left join basic.payment p on u.game_account_id=p.game_account_id group by 1
SQL
복사
김종선 select case when p.game_account_id is not null then '결제함' else '결제안함' end as gb, COUNT(distinct u.game_account_id) as usercnt from basic.users u left join basic.payment p on u.game_account_id = p.game_account_id group by gb
SQL
복사