PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > (Mysql 3.23] Query with SUM wrong
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
(Mysql 3.23] Query with SUM wrong

Réponse
 
LinkBack Outils de la discussion
Vieux 21/04/2006, 11h31   #1 (permalink)
trihanhcie@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut (Mysql 3.23] Query with SUM wrong

Hi,

Well the following query is not the one i will use but it's the same
prob :

SELECT sum(country_id ) , count( country_id )
FROM Tbl_Country, Tbl_config
WHERE country_id =1

Well ...the result should be sum(country_id )= 1 et count( country_id
) = 1... but I have :
sum(country_id )= 4 et count( country_id ) = 4...
The number of entries in Tbl_Config is also 4.... I know that adding
Tbl_config behind is useless but it was just a test... How come i don't
have 1 and 1 as result?

Thanks

  Réponse avec citation
Vieux 21/04/2006, 11h52   #2 (permalink)
Aggro
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: (Mysql 3.23] Query with SUM wrong

trihanhcie@gmail.com wrote:
> Hi,
>
> Well the following query is not the one i will use but it's the same
> prob :
>
> SELECT sum(country_id ) , count( country_id )
> FROM Tbl_Country, Tbl_config
> WHERE country_id =1
>
> Well ...the result should be sum(country_id )= 1 et count( country_id
> ) = 1... but I have :
> sum(country_id )= 4 et count( country_id ) = 4...
> The number of entries in Tbl_Config is also 4.... I know that adding
> Tbl_config behind is useless but it was just a test... How come i don't
> have 1 and 1 as result?


Because you make a join. That means that for each row in the first
table, your query will seek a partner from the other table. Without any
where conditions, that would mean that amount of returned rows is
rows_in_first_table * rows_in_second_table. Try this query:


SELECT *
FROM Tbl_Country, Tbl_config
WHERE country_id =1;

And you perhaps understand better why you are getting the numbers you
are getting.

Your problem could perhaps be fixed by adjusting the WHERE conditions of
your query, but that would require a knowledge of what you actually want
to get, so I can't give you any clear answer for that one. But perhaps
something like this:

SELECT *
FROM Tbl_Country, Tbl_config
WHERE Tbl_Country.config_id=Tbl_config.id AND country_id =1;
  Réponse avec citation
Vieux 21/04/2006, 13h23   #3 (permalink)
trihanhcie@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: (Mysql 3.23] Query with SUM wrong

Thanks ^^ It's quite logic in fact well I made it more precise and
it's working for the moment... hoping it will still be ok in the future


Thanks again

  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 14h46.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08396 seconds with 11 queries