|
Posted by Shelly on 10/06/07 19:43
"Colleen" <colleenrobledo@gmail.com> wrote in message
news:1191694561.785242.199670@o80g2000hse.googlegroups.com...
> Hello!
>
> I've only been dabbling in PHP and MySQL for a few months.
>
> I'm trying to find out if there's a query/function similar to the RANK
> function in Excel.
>
> What I want to be able to do is take a list of dates from a particular
> table field, and be able to rank each record in the order within which
> in falls in those range of dates, because records are not always
> entered in chronological order.
>
> Here's a partial sampling of my table, showing the relevant fields for
> this query.
>
> casualtyID deathdate
> 1 2003-12-01
> 2 2007-06-20
> 3 2002-08-30
> 4 2007-01-01
> 5 2005-04-11
>
> So, from this "ranking" query (that would generate the result $rank),
> I want to be able to say:
> echo "$casualtyID is the number $rank casualty to die in the current
> wars in Iraq and Afghanistan\n";
>
>
> Thank you!
>
> Colleen Robledo
> http://www.colleenrobledo.info
>
select casualtyID, deathdate from the_table order by deathdate
Then the results will be in deathdate order and as you loop through the
results you know what the index/rank of each individual casualtyID is.
Shelly
Navigation:
[Reply to this message]
|