728x90
in PostgreSQL
SELECT FIRST_VALUE(VALUE) OVER(PARTITION BY STOCK_NAME ORDER BY DATE)
FROM STOCK;
SQL Error [42601]: ERROR: Aggregate window functions with an ORDER BY clause require a frame clause
TSLA / 2023-08-13 / 200
TSLA / 2023-08-14 / 210
TSLA / 2023-08-15 / 220
TSLA / 2023-08-16 / 230
first_value๋ฅผ ์ฌ์ฉํ ๋ ODRER BY ๊ตฌ๋ฌธ์์ ๊ฐ๋ณ Row์ ๋ํ DATE๋ฅผ ์ด๋ป๊ฒ ์ ๋ ฌํ ์ง ์ง์ ๋์ง ์์ ์๊ธด ์ค๋ฅ
"order by value rows between [front] preceding and [back] following"์ผ๋ก row์ ๊ธฐ์ค ๋์์ window ์๋ฅผ ์ง์ ํ ์ ์๋ค.
SELECT FIRST_VALUE(VALUE) OVER(PARTITION BY STOCK_NAME ORDER BY DATE) (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
FROM STOCK;
DATE์ ๋ํด ์ ์ฒด ROW ์ ๋ ฌ์ ๊ฐ๋ณ์ ์ผ๋ก ์ํํ๋ค.
order by value rows between 1 preceding and 2 following
=>
๋ฐ์ํ
'๐ข๏ธ Database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Hadoop] Namenode Error (localhost: ERROR: Cannot set priority of datanode process ) (0) | 2023.11.12 |
---|---|
[WSL] ssh: connect to host localhost port 22: Connection refused (0) | 2023.10.29 |
[SQL] LEFT, REPLACE, SUBSTRING (0) | 2023.08.21 |
[SQL] LIKE (0) | 2023.08.20 |
[SQL] NULLIF, NVL(COALESCE) ํจ์ (0) | 2023.08.19 |