일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- null
- 네이버스마트 에디터
- spring form tag
- @RequestBody
- RADIO
- 한글
- php
- java
- exception
- switch
- SSL
- json
- maven
- 스크립트
- html
- 전자정부 표준프레임워크
- 웹 플랫폼 설치 관리자
- 오라클
- Oracle
- HTML5
- 톰캣
- 이클립스
- 호환성
- checbox
- DB
- MYSQL
- JSTL
- jquery
- 문자열
- 날짜
- Today
- Total
개인적인 정리
[Oracle] NTH_VALUE() 본문
오라클 NTH_VALUE()
NTH_VALUE()
-
NTH_VALUE(measure_expr, n) FROM [FIRST | LAST] [RESPECT | IGNORE] NULLS OVER (analytic_clause)
의 형태
NTH_VALUE returns the measure_expr value of the nth row in the window defined by the analytic_clause. The returned value has the data type of the measure_expr.
- [RESPECT | IGNORE] NULLS determines whether null values of measure_expr are included in or eliminated from the calculation. The default is RESPECT NULLS.
- n dertimines the nth fow for which the measure value is to be returned. n can be a constant, bind variable, column, or an expression involving them, as long as it resovles to a positive integer. The function returns NULL if the data source window has fewer than n rows. If n is null, then the function returns an error.
- FROM [FIRST | LAST] determines whether the calculation begins at the first or last row of the window. The default is from FIRST.
If you omit the windowing-clause of the analytic_clause, it defaults to RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. This default sometimes returns an unexprected value for NTH_VALUE... FROM LAST... , because the last value in the window is at the bottom of the window, which is not fixed. It keeps changing as the current row changes. For expected results, specify the windowing_clause as RNAGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. Alternatively, you can specify the windowing_clause as RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING.
오라클 SH 계정으로 테스트 가능
SQL>
SELECT
prod_id,
channel_id,
MIN(amount_sold),
NTH_VALUE(MIN(amount_sold), 2) OVER (PARTITION BY prod_id ORDER BY channel_id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) nv
FROM sales
WHERE prod_id BETWEEN 14 AND 16
GROUP BY prod_id, channel_id ;
'DB > ORACLE' 카테고리의 다른 글
[Oracle] NUMTOYMINTERVAL() (0) | 2020.04.13 |
---|---|
[Oracle]NUMTODSINTERVAL() (0) | 2020.04.13 |
[Oralce] NULLIF() (0) | 2020.04.13 |
[Oracle] NTILE() (0) | 2020.04.13 |
[Oracle] NEXT_DAY() (0) | 2020.04.10 |
[Oracle] NCHR() (0) | 2020.04.10 |
[Oracle] NANVL() (0) | 2020.04.10 |
[Oracle] MONTHS_BETWEEN() (0) | 2020.04.10 |