From: Greg Sabino Mullane <greg@turnstep.com>
To: pgsql-sql@postgresql.org
Subject: Re: equivalent of oracle rank() in postgres
Date: Tue, 22 Mar 2005 02:52:53 -0000
Message-ID: <31bf0e84213104473bc7c80d2b0a9fb3@biglumber.com> (raw)
In-Reply-To: <2EB549AAAFEA264FA926269A5BD5E9EB14657F@certsrv.satyam.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> Jus wanted the equivalent for rank() as in tis example..
> SELECT *
> FROM (
> SELECT employee_id, last_name, salary,
> RANK() OVER (ORDER BY salary DESC) EMPRANK
> FROM employees)
> WHERE emprank = 3;
There is no direct equivalent to rank(), but there are certainly
other ways to get the results. The above query can be written in
PostgreSQL as:
SELECT employee_id, last_name, salary
FROM employees
WHERE salary =
(SELECT DISTINCT salary FROM employees ORDER BY salary DESC OFFSET 2 LIMIT 1);
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200503212152
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iD8DBQFCP4hwvJuQZxSWSsgRAoKPAKDE0pB4NueE0Dh9EfJiXw79SvCDoACcC4xb
ydxVgK9DgGHQXJqFIrlHIIo=
=GRIX
-----END PGP SIGNATURE-----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: greg@turnstep.com
Subject: Re: equivalent of oracle rank() in postgres
In-Reply-To: <31bf0e84213104473bc7c80d2b0a9fb3@biglumber.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox