SQL

[SQL 과제 _ 1.3]

thebuck104 2024. 7. 4. 02:56
#문제1
select count(1) from payment p
where pay_type like "%MONEY%" and p.pay_amount >= 500000;

#문제2
select pay_type, min(pay_amount) from payment p
group by pay_type 
having min(pay_amount) >= 500;

#문제3
select serverno, count(distinct p.game_account_id) users_with_payment  
from payment p
inner join users u on u.game_account_id = p.game_account_id
group by serverno
order by 1;

#문제4
select u.game_account_id, 
count(distinct u.game_actor_id) actorcnt,
sum(p.pay_amount)
from users u
inner join payment p on u.game_account_id =p.game_account_id 
where p.pay_type like "%CARD%" and u.serverno >= 2
group by 1
order by 3 desc;

#문제5
select game_account_id , `date` last_login_date , logid ,ip_addr , `date` ,game_actor_id 
from users u
where (game_account_id , `date`) in 
(select game_account_id , max(`date`)
from users
group by game_account_id)
order by 2 desc;