Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sum records from three different tables into one
Message
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00578624
Message ID:
00578647
Vues:
22
This message has been marked as the solution to the initial question of the thread.
SELECT Namefield, hours1 AS hours FROM TableA ; 
  UNION ALL ;
  SELECT Namefield, hours2 AS hours FROM TableB ; 
  UNION ALL ;
  SELECT Namefield, hours3 AS hours FROM TableC ; 
  INTO CURSOR temp1

SELECT Namefield, SUM(hours) FROM temp1 ;
  GROUP BY 1 ;
INTO CURSOR crsResult
>I have three separate tables that have the names of individuals (the same name might appear in one, two or all of the tables). Each of the tables contain varying numeric data but I would like to create a query that calculates the sum of the records from each table according to the individuals name.
>Should this be a right join or full join?
>What code would make this query work?
>
>e.g.
>Table A               Table B             Table C
>Henry                  Henry                Henry
>14 Hours             9 Hours              12 Hours
>My query should create a Table D which shows Henry as having a total of 35 Hours. The field for the number of hours has a different name in each table but the field for the person's name is the same.
>Thank you
>Max
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform