Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do you solve this join issue...
Message
 
 
À
12/04/2002 13:22:59
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00644420
Message ID:
00644429
Vues:
18
Try
SELECT sum(m.rgcur), 
   (SELECT sum(t.tax_cur) FROM py_ehtax t 
        WHERE t.ehmast_id = m.ehmast_id ),
   (SELECT sum(h.hours) FROM py_ehhour h 
        WHERE h.ehmast_id = m.ehmast_id )
FROM py_ehmast m
GROUP BY ee_id
>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
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform