Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to factor my cursor?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01151893
Message ID:
01151899
Views:
23
This message has been marked as the solution to the initial question of the thread.
>I have a cursor with records as follows:
>
>Route  Class  SType  Family  PrevPassngers PrevMult PrevNumTrips CurrPassengers CurrMult  CurrNumTrips
>0588          D      G                386      1.75       676.79
>0588          D      G                                                     147      1.00        147.00
>0588          D      G                                                     194      1.00        194.00
>0588          D      G                                                     313      1.00        213.00
>0011          C      B                 33      1.75        57.86
>0011          C      B                                                       1      1.00          1.00
>0016          C      E                675      1.75      1183.51
>0016          C      E                                                       3      1.00          3.00
>0016          C      E                                                      17      1.00         17.00
>0016          C      E                                                      10      1.00         10.00
>...
>
>and need to condense/combine them into 1 rec for each Route/ClassStype/Family combo, i.e.
>
>Route  Class  SType  Family  PrevPassngers PrevMult PrevNumTrips CurrPassengers CurrMult  CurrNumTrips
>0588          D      G                386      1.75       676.79           554      1.00        554.00
>0011          C      B                 33      1.75        57.86             1      1.00          1.00
>0016          C      E                675      1.75      1183.51            30      1.00         30.00
>
>Is there a quick SQLish way of doing this without having to loop and append and accumulate and all that?
>There could just as easily be many recs to the left (prev) side to one or few on the right (curr)
>
>'ppreciate it
>
>Terry
SELECT Route, Class, SType, Family,;
       SUM(PrevPassngers) AS PrevPassngers,;
       SUM(PrevMult)      AS PrevMult,;
       SUM(PrevNumTrips)  AS PrevNumTrips,;
       SUM(CurrPassengers)AS CurrPassengers,;
       MAX(CurrMult)      AS CurrMult,;
       SUM(CurrNumTrips)  AS CurrNumTrips;
FROM MyTable;
GROUP BY Route, Class, SType, Family;
INTO CURSOR crsTest
BROSE NORMAL
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform