Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sum up a set of field
Message
De
19/10/2010 14:14:14
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
19/10/2010 14:03:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01486130
Message ID:
01486177
Vues:
50
The original records stay in the table. The result of the SELECT goes to a cursor (a temporary table).

If you want to have the totals in the original table, I think you might start with the SELECT ... GROUP BY to have the totals. After that, you might index the cursor, do a SET RELATION (from the table into the cursor), and do a simple REPLACE. Or write some kind of loop.

>That's what i want but is there a way to keep original set of records in the table.
>>>I need to sum a set of fields by an other field in a table and i'd like to know if my idea is good enough.
>>>(It seemed to be a bit clumsy).
>>>The table is like this
>>>A B C
>>>aa 1 1
>>>bb 2
>>>bb 3
>>>bb 4 9
>>>cc 5 5
>>>dd 6
>>>dd 7
>>>dd 8 21
>>>
>>>So I should sum field "B" by field "A" in the filed "C". I would use 2 do while loops, one of them goes through the table and the other one would sum up the filed B if there are more than two identical ones in field "A". Does it seem ok?
>>
>>I am not sure what exactly you want, but if you want the total for each different text in field "A", a SELECT with a GROUP BY clause will do the job, for example:
>>
>>
>>select a, sum(b) as total_b;
>>  from MyTable;
>>  group by a;
>>  into cursor Temp
>>
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform