PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Query , please..
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Query , please..

Réponse
 
LinkBack Outils de la discussion
Vieux 11/12/2007, 16h38   #1
Anders Norrbring
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Query , please..

I'm looking at a situation I haven't run into before, and I'm a bit
puzzled by it.

I have this table structure:

Table USERS: userid, class
Table OBJECT: userid, class, result

Now I want to query the database for a certain user's result in a
specified class, which is very, very easy. No problems.

But, I also want to find out the user's position relative to others
depending on the result.

So, if the specified user's result is the 9:th best of all of the users,
I want to have a reply from the DB query that say he has position number 9.

I really can't figure out how to do that... Somehow I have to make MySQL
calculate the position based on the value in the result column.

  Réponse avec citation
Vieux 11/12/2007, 16h46   #2
Rob Wultsch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Query , please..

On Dec 11, 2007 8:38 AM, Anders Norrbring <lists@norrbring.se> wrote:
> I'm looking at a situation I haven't run into before, and I'm a bit
> puzzled by it.
>
> I have this table structure:
>
> Table USERS: userid, class
> Table OBJECT: userid, class, result
>
> Now I want to query the database for a certain user's result in a
> specified class, which is very, very easy. No problems.
>
> But, I also want to find out the user's position relative to others
> depending on the result.
>
> So, if the specified user's result is the 9:th best of all of the users,
> I want to have a reply from the DB query that say he has position number 9.
>
> I really can't figure out how to do that... Somehow I have to make MySQL
> calculate the position based on the value in the result column.


Take a look at http://arjen-lentz.livejournal.com/55083.html . Very
similar ideas in play, though you also have a join.

The basic idea is that you do a count on the number of users that have
a lower score.
  Réponse avec citation
Vieux 11/12/2007, 17h08   #3
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Query , please..


On Dec 11, 2007, at 10:46 AM, Rob Wultsch wrote:

> On Dec 11, 2007 8:38 AM, Anders Norrbring <lists@norrbring.se> wrote:
>> I'm looking at a situation I haven't run into before, and I'm a bit
>> puzzled by it.
>>
>> I have this table structure:
>>
>> Table USERS: userid, class
>> Table OBJECT: userid, class, result
>>
>> Now I want to query the database for a certain user's result in a
>> specified class, which is very, very easy. No problems.
>>
>> But, I also want to find out the user's position relative to others
>> depending on the result.
>>
>> So, if the specified user's result is the 9:th best of all of the
>> users,
>> I want to have a reply from the DB query that say he has position
>> number 9.
>>
>> I really can't figure out how to do that... Somehow I have to make
>> MySQL
>> calculate the position based on the value in the result column.

>
> Take a look at http://arjen-lentz.livejournal.com/55083.html . Very
> similar ideas in play, though you also have a join.
>
> The basic idea is that you do a count on the number of users that have
> a lower score.


Is there any reason you wouldn't want to count the people in front of
you and add 1 to get your place in line? It seems like depending on
where you are, that may be a shorter number to count

But I don't know anything about how to do stuff off of separate tables
yet still trying to grasp that


>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=japruim@raoset.com
>
>


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@raoset.com


  Réponse avec citation
Vieux 11/12/2007, 19h18   #4
Peter Brawley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Query , please..

Anders,

>I also want to find out the user's position relative to others

depending on the result.

For a given pUserID, something like this?

SELECT userid,result,rank
FROM (
SELECT o1.userid,o1.result,COUNT(o2.result) AS rank
FROM object o1
JOIN object o2 ON o1.result < o2.result OR (o1.result=o2.result AND
o1.userid=o2.userid)
GROUP BY o1.userid,o1.result
)
WHERE userid = pUserID;

PB

-----

Anders Norrbring wrote:
> I'm looking at a situation I haven't run into before, and I'm a bit
> puzzled by it.
>
> I have this table structure:
>
> Table USERS: userid, class
> Table OBJECT: userid, class, result
>
> Now I want to query the database for a certain user's result in a
> specified class, which is very, very easy. No problems.
>
> But, I also want to find out the user's position relative to others
> depending on the result.
>
> So, if the specified user's result is the 9:th best of all of the
> users, I want to have a reply from the DB query that say he has
> position number 9.
>
> I really can't figure out how to do that... Somehow I have to make
> MySQL calculate the position based on the value in the result column.
>
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h18.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10293 seconds with 12 queries