본문 바로가기

카테고리 없음

레스토랑의 요일별 VIP

728x90

https://solvesql.com/problems/restaurant-vip/

 

https://solvesql.com/problems/restaurant-vip/

 

solvesql.com

 

select total_bill,tip,sex,smoker,day,time,size
from (
select *, rank() over(PARTITION by day order by total_bill desc) as rk
from tips
)
where rk = 1

 

가장 큰 컬럼을 찾으면 되는거라 rank나 row_number() 윈도우 함수 쓰는게 편하다고 생각해서 풀이함

윈도우 함수를 안쓴다면 서브쿼리에 in , max 함수 써도 충분하다 생각!

728x90