PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Complicated COUNT or DISTINCT with JOIN, Anyone?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Complicated COUNT or DISTINCT with JOIN, Anyone?

Réponse
 
LinkBack Outils de la discussion
Vieux 19/10/2007, 17h03   #1
pim@impulzief.nl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Complicated COUNT or DISTINCT with JOIN, Anyone?

Dear All,

I just can't seem to get myself a nice query.
I have a table with data about people meeting eachother. They meet
randomly and now I want to show a history, about who you met and how
many times.

Table and contents could be as followed:

userleft_id | userright_id

1 2
2 4
5 2
6 1
4 2

As you can see, users 4 and 2 met eachother twice, the rest only once.
So if I want to show user 2 who he met results should be:

User 2 met:

1 1 time
4 2 times
5 1 time


How can I get this result from here? The table as thousands of rows.
Of course, I could retrieve everything in PHP and compare everything
but I guess it could be done in SQL as well.

In another table the names of all these people can be found which I
want to have as well in a JOIN.
Normally, I would use

INNER JOIN usernames ON meetings.userleft_id=usernames.user_id

but this time I do not know whether it is userleft_id or userright_id
of who I want to have the name.


Anyone have a suggestion?


Kind regards,


Pim Zeekoers

  Réponse avec citation
Vieux 19/10/2007, 17h40   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Complicated COUNT or DISTINCT with JOIN, Anyone?

On 19 Oct, 16:03, p...@impulzief.nl wrote:
> Dear All,
>
> I just can't seem to get myself a nice query.
> I have a table with data about people meeting eachother. They meet
> randomly and now I want to show a history, about who you met and how
> many times.
>
> Table and contents could be as followed:
>
> userleft_id | userright_id
>
> 1 2
> 2 4
> 5 2
> 6 1
> 4 2
>
> As you can see, users 4 and 2 met eachother twice, the rest only once.
> So if I want to show user 2 who he met results should be:
>
> User 2 met:
>
> 1 1 time
> 4 2 times
> 5 1 time
>
> How can I get this result from here? The table as thousands of rows.
> Of course, I could retrieve everything in PHP and compare everything
> but I guess it could be done in SQL as well.
>
> In another table the names of all these people can be found which I
> want to have as well in a JOIN.
> Normally, I would use
>
> INNER JOIN usernames ON meetings.userleft_id=usernames.user_id
>
> but this time I do not know whether it is userleft_id or userright_id
> of who I want to have the name.
>
> Anyone have a suggestion?
>
> Kind regards,
>
> Pim Zeekoers


UNION 2 queries, one based on your person being in userleft and the
other based on them being in userright, then sum the results in a
query containing the union.

  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 00h40.


Édité par : vBulletin® version 3.7.3
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,08775 seconds with 10 queries