| List: | General Discussion | « Previous MessageNext Message » | |
| From: | Maciej Dobrzanski | Date: | March 24 2007 12:05am |
| Subject: | Re: Finding a record in a result set | ||
| View as plain text | |||
"James Tu" <jtu@stripped> wrote in message = news:FFE2B162-EDC4-43F3-BF89-E798FBA1F97E@ style="color:#666">stripped... > I want to do a query of all employees from Maine, ordered by hiring =20 > date, and figure out where Joe falls in that list. (i.e. which record = > number is he?) I think this can only be accomplished with a temporary table. SET @n:=3D0; SELECT t.name, t.n FROM (SELECT @n:=3D@n+1 AS n, name FROM t WHERE state = =3D 'Maine' ORDER BY hire DESC) t WHERE t.name =3D 'Foo'; This query though may not be suitable for most situations as its = performance depends heavly on the size of the derived table.=20 Maciek
