Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL statement problem ?
Message
De
04/11/1998 12:06:06
 
 
À
04/11/1998 11:54:34
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00154383
Message ID:
00154391
Vues:
15
>i tried to join three table and use sql statement to calculate the result (sum of quantity).
>let me list out the tree table.
>table1: stock
>field: item_name (printer,harddisk)
>
>table2: purchase
>field: item_name , quantity
>record: printer, 2
> harddisk, 4
> printer,4
> harddisk, 3
>
>table3: sales
>field: item_name, quantity
>record: harddisk, 4
> printer, 3
>
>i use sql to calculate the sum of quatity for table2 and table3
>but the result give me two times of the actual result
>my code is like this:
>
>>SELECT stock.item_name,SUM(purchase.quantity) AS quantity1,SUMsales.quantity) AS quantity2;
>>FROM database1!stock,database1!purchase,database1!sales;
>>WHERE stock.item_name=purchase.item_name;
>>AND stock.item_name=sales.item_name;
>>group by stock.item_name;
>>order by stock.item_name
>
>Can anyone tell me what's wrong and give me the right sql statement.
>thanks

SELECT stock.item_name,SUM(purchase.quantity) AS quantity1 ;
FROM stock,purchase ;
WHERE stock.item_name=purchase.item_name ;
GROUP by stock.item_name ;
ORDER by 1 ;
UNION SELECT stock.item_name,SUM(sales.quantity) AS quantity1 ;
FROM stock,sales ;
WHERE stock.item_name=sales.item_name;
GROUP by stock.item_name;
Edward Pikman
Independent Consultant
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform