CREATE TEMPORARY TABLE empsalary (
depname varchar,
empno bigint,
salary int,
enroll_date date
);
INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-08-01'), ('sales', 1, 5000, '2006-10-01'),
('personnel', 5, 3500, '2007-12-10'),('sales', 4, 4800, '2007-08-08'),('personnel', 2, 3900, '2006-12-23'),
('develop', 7, 4200, '2008-01-01'),('develop', 9, 4500, '2008-01-01'),('sales', 3, 4800, '2007-08-01'),
('develop', 8, 6000, '2006-10-01'),('develop', 11, 5200, '2007-08-15');
explain verbose select rank() over (partition by depname order by salary), percent_rank() over(partition by depname order by salary asc) from empsalary;
QUERY PLAN
------------------------------------------------------------------------------------------
WindowAgg (cost=10000000074.54..10000000114.66 rows=1070 width=52)
Output: (rank() OVER (?)), percent_rank() OVER (?), salary, depname
-> WindowAgg (cost=10000000074.54..10000000095.94 rows=1070 width=44)
Output: salary, depname, rank() OVER (?)
-> Sort (cost=10000000074.54..10000000077.21 rows=1070 width=36)
Output: salary, depname
Sort Key: empsalary.depname, empsalary.salary
-> Seq Scan on pg_temp_7.empsalary (cost=0.00..20.70 rows=1070 width=36)
Output: salary, depname
typedef struct SortBy
{
NodeTag type;
Node *node; /* expression to sort on */
SortByDir sortby_dir; /* ASC/DESC/USING/default */
SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
List *useOp; /* name of op to use, if SORTBY_USING */
int location; /* operator location, or -1 if none/unknown */
} SortBy;