Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do you solve this join issue...
Message
De
12/04/2002 13:22:59
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
How do you solve this join issue...
Divers
Thread ID:
00644420
Message ID:
00644420
Vues:
51
Hi All,

I have a query where I want to sum() data from three tables. Heres the problem though. I have a 'parent' record which has some values in it, then two child tables...

So, if I do my first query:

SELECT sum(rgcur) from py_ehmast
GROUP BY ee_id

I get the correct value. Then I add the child table..

SELECT sum(m.rgcur), sum(t.tax_cur)
FROM py_ehmast m
JOIN py_ehtax t ON m.ehmast_id = t.ehmast_id
GROUP BY ee_id

Now, I get the correct tax_cur sum, but the m.rgcur sum is overstated.

Then when I add the third table...

SELECT sum(m.rgcur), sum(t.tax_cur), sum(h.hours)
FROM py_ehmast m
JOIN py_ehtax t ON m.ehmast_id = t.ehmast_id
JOIN py_ehhour h on m.ehmast_id = h.ehmast_id
GROUP BY ee_id

Of course, I get even different numbers... I know WHY this is happening, I am wondering what the easiest way to solve this is, without doing three selects?

Thanks,
BOb
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform