Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL-Select that sums
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00750295
Message ID:
00750345
Vues:
19
>Winn,
>
>As soon as you group the records, some of the fields are not relevant any more. In your example, you may want the following, assuming that there is a one-to-one relationship between lotName and line:
>
>
>SELECT lotName, line, SUM(lbs) AS sum_lbs FROM myTable GROUP BY line into cursor cursor1
>
>This will return 3 records from your example table. If you include item and lbs fields, it will only have the value of one of the records in the group...so they are meaningless.

Steve, that code won't work in VFP8 (by default, at least) -- if you include a GROUP BY clause, any field not in the clause must be in an aggregate function in the field list.

This could be rewritten as either:
SELECT lotName, line, SUM(lbs) AS sum_lbs ;
   FROM myTable ;
   GROUP BY lotname, line ;
   INTO CURSOR cursor1
or
SELECT MIN(lotName), line, SUM(lbs) AS sum_lbs ;
   FROM myTable ;
   GROUP BY line ;
   INTO CURSOR cursor1
to make it work.

Alternately, you could use the double-secret-make-it-work-like-70 SYS function. :-)
My blog
My consulting page
My home page

Member of the Trim Your Auto-Quote Campaign!
What's another word for thesaurus?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform