IT 공부방 [기본지식 정리]/데이터베이스 (DB)
105. MySQL - 윈도우 함수
cTosMaster
2025. 3. 26. 17:22
1. 윈도우 함수 종류
Table 14.30 Window Functions
NameDescription
CUME_DIST() | Cumulative distribution value |
DENSE_RANK() | Rank of current row within its partition, without gaps |
FIRST_VALUE() | Value of argument from first row of window frame |
LAG() | Value of argument from row lagging current row within partition |
LAST_VALUE() | Value of argument from last row of window frame |
LEAD() | Value of argument from row leading current row within partition |
NTH_VALUE() | Value of argument from N-th row of window frame |
NTILE() | Bucket number of current row within its partition. |
PERCENT_RANK() | Percentage rank value |
RANK() | Rank of current row within its partition, with gaps |
ROW_NUMBER() | Number of current row within its partition |
>> MySQL :: MySQL 8.4 Reference Manual :: 14.20.1 Window Function Descriptions
MySQL :: MySQL 8.4 Reference Manual :: 14.20.1 Window Function Descriptions
14.20.1 Window Function Descriptions This section describes nonaggregate window functions that, for each row from a query, perform a calculation using rows related to that row. Most aggregate functions also can be used as window functions; see Section 14
dev.mysql.com
2. 윈도우 함수 사용 예제
-> 윈도우 함수는 항상 over () 와 함께 사용된다. [ over_clause 구문이라고 함.]
1) row_number
select row_number() over (order by ename) as "순번", ename, sal from emp;
2) RANK()