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 > Multiple Count in 1 Query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Multiple Count in 1 Query

Réponse
 
LinkBack Outils de la discussion
Vieux 23/09/2007, 22h07   #1
JSOUL Rocks
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Multiple Count in 1 Query

I've got a few different tables that track video game consoles people
use in their profile. The tables are below. I'm trying to do two
counts/sorts and display them properly.

(1) sort the fields by country
(2) In each country, display the number consoles owned by members
sorted by brand and model. So it should output like this:

country, brand name, model number, number of owners
US, microsoft, xbox1, 5432
US, sony, playstation1, 4345
US, sony, playstation2, 5456
Mexico, microsoft, xbox1, 4432
Mexico, sony, playstation2, 4545

etc.

The tables I have are as follows and the problem is that I could
reference 2 tables but not 3. The challenge is that the reference
between:

(1) members and countries tables (countrynum and countryname)
(2) members and consoles tables (consolemodelid = consoleid)
(3) consoles and consolebrands tables (consolebrandid = brandsid)

and then each ID has to do a lookup to return the name associated with
the ID, the console model to consoleid, the brandsname to the
brandsid, and the countryname to the countryid.

members table
userid
username
countrynum
consolemodelid

consoles table
consoleid
consolemodel
consolebrandid

countries table
countryid
countryname

consolebrands table
brandsid
brandsname

Right now I've been working with this query but I'm can't handle all
these tables since there are now three cross referenced instead of
just two:

SELECT consolebrands.brandsname, members.consolemodelid, count( * )
AS count
FROM members, consoles, consolebrands, countries where (
(members.consolemodelid = consoles.consoleid) and
(consoles.consolebrandid = consolebrands.id) )
GROUP BY consolebrands.brandsname
ORDER BY count DESC

And I'm totally stuck! As it has been a while, I'm hoping someone can
me out as I learn more complex queries. Thank you!



  Réponse avec citation
Vieux 24/09/2007, 10h16   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Multiple Count in 1 Query

On 23 Sep, 22:07, JSOUL Rocks
<tkd_NO_SPAM_inthecity@yah_NO_SPAM_oo.com> wrote:
> I've got a few different tables that track video game consoles people
> use in their profile. The tables are below. I'm trying to do two
> counts/sorts and display them properly.
>
> (1) sort the fields by country
> (2) In each country, display the number consoles owned by members
> sorted by brand and model. So it should output like this:
>
> country, brand name, model number, number of owners
> US, microsoft, xbox1, 5432
> US, sony, playstation1, 4345
> US, sony, playstation2, 5456
> Mexico, microsoft, xbox1, 4432
> Mexico, sony, playstation2, 4545
>
> etc.
>
> The tables I have are as follows and the problem is that I could
> reference 2 tables but not 3. The challenge is that the reference
> between:
>
> (1) members and countries tables (countrynum and countryname)
> (2) members and consoles tables (consolemodelid = consoleid)
> (3) consoles and consolebrands tables (consolebrandid = brandsid)
>
> and then each ID has to do a lookup to return the name associated with
> the ID, the console model to consoleid, the brandsname to the
> brandsid, and the countryname to the countryid.
>
> members table
> userid
> username
> countrynum
> consolemodelid
>
> consoles table
> consoleid
> consolemodel
> consolebrandid
>
> countries table
> countryid
> countryname
>
> consolebrands table
> brandsid
> brandsname
>
> Right now I've been working with this query but I'm can't handle all
> these tables since there are now three cross referenced instead of
> just two:
>
> SELECT consolebrands.brandsname, members.consolemodelid, count( * )
> AS count
> FROM members, consoles, consolebrands, countries where (
> (members.consolemodelid = consoles.consoleid) and
> (consoles.consolebrandid = consolebrands.id) )
> GROUP BY consolebrands.brandsname
> ORDER BY count DESC
>
> And I'm totally stuck! As it has been a while, I'm hoping someone can
> me out as I learn more complex queries. Thank you!


Do not multi-post. Cross-post if you must but don't multi post It
wastes
people's time. http://www.blakjak.demon.co.uk/mul_crss.htm.

  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 10h38.


É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,10264 seconds with 10 queries