Tools/- SQL

[SQL] solvesql | 레스토랑 요일 별 구매금액 Top 3 영수증

스위민 2025. 2. 14. 10:28

문제

https://solvesql.com/problems/top-3-bill/

 

https://solvesql.com/problems/top-3-bill/

 

solvesql.com

 

코드

SELECT
  day,
  time,
  sex,
  total_bill
from
(select
  *,
  dense_rank() over (partition by day order by total_bill desc) as rnk
from tips) as t
where rnk <= 3

-- 4분

 

문제 풀이

  • dense_rank() over

중복값이 있으면

1 / 2 2 / 3

이런식으로 출력해주는 게 dense_rank (순위를 빽빽하게 매긴다 -> dense하다는 식으로 외웠다)

 

참고로 rank()는 1 / 2 2 / 4 로 순위가 매겨진다.

 

느낀 점

없음 !