postgreSQL버전 확인

select version();


오늘 날짜보기

select current_date;


그룹별 랭크먹이기

SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary DESC) FROM empsalary;



SELECT salary, sum(salary) OVER () FROM empsalary; salary


 | sum --------+------- 5200 | 47100 5000 | 47100 1. There are options to define the window frame in other ways, but this tutorial does not cover them. See Section 4.2.8 for details. 18 Chapter 3. Advanced Features 3500 | 47100 4800 | 47100 3900 | 47100 4200 | 47100 4500 | 47100 4800 | 47100 6000 | 47100 5200 | 47100 (10 rows) Above, since there is no ORDER BY in the OVER clause, the window frame is the same as the partition, which for lack of PARTITION BY is the whole table; in other words each sum is taken over the whole table and so we get the same result for each output row. But if we add an ORDER BY clause, we get very different results: 



SELECT salary, sum(salary) OVER (ORDER BY salary) FROM empsalary; salary | sum --------+------- 3500 | 3500 3900 | 7400 4200 | 11600 4500 | 16100 4800 | 25700 4800 | 25700 5000 | 30700 5200 | 41100 5200 | 41100 6000 | 47100 (10 rows) 


'COMPUTER > DATABASE' 카테고리의 다른 글

PostgreSQL Tips  (0) 2015.10.26
PostgreSQL 컬럼수 제한  (0) 2015.10.26
altibase db connection 예제  (0) 2014.09.17
sql 여러행 비교 - 서브쿼리가 여러개의 행을 리턴할 때  (0) 2013.10.10
sql plus 몇가지 팁  (0) 2013.10.08

+ Recent posts