Ranking function in PHP/MySQL - Page 3

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: Ranking function in PHP/MySQL

On Sat, 06 Oct 2007 18:16:01 +0000, Colleen wrote:

Quoted text here. Click to load it

I'm not sure about MySQL but Oracle can do the following:
select id,
       dense_rank() over (order by deathdate) as rnk
from table;

You can do that on the classic EMP table and it goes like this:

  1  select ename,hiredate,
  2         dense_rank() over (order by hiredate) as rnk
  3* from emp
SQL> /

---------- --------- ----------
SMITH      17-DEC-80          1
ALLEN      20-FEB-81          2
WARD       22-FEB-81          3
JONES      02-APR-81          4
BLAKE      01-MAY-81          5
CLARK      09-JUN-81          6
TURNER     08-SEP-81          7
MARTIN     28-SEP-81          8
KING       17-NOV-81          9
JAMES      03-DEC-81         10
FORD       03-DEC-81         10
MILLER     23-JAN-82         11
SCOTT      19-APR-87         12
ADAMS      23-MAY-87         13

14 rows selected.


You can do that with Oracle Express, too. It's called "analytic function".


Site Timeline