Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select Statement help
Message
From
08/06/2002 08:22:47
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
07/06/2002 14:10:53
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00666106
Message ID:
00666283
Views:
16
>Hi All,
> I have need of a select statement that adds certain values and returns a single record out of, for example, two records.
>
>
 1   GLOC  20228       9.33247      1.10   92.16   1    T   P   1
> 2   GLOC  17533       5.00000      1.10   92.16   1    T   P   2
>
>The select statement would preferably return
>
>
1   GLOC  20228       14.33247      1.10   92.16   1    T   P   1
>
>I guess what I am saying is that I want to add one value out of one record to the other value in the first. Does anyone have any ideas?
>Thanks,

Win if I understand you right you want to :
1) Sum some fields
2) Get first record of some key (GLOC here)

Aggregate functions by nature always get the last entry for non-aggregate fields. Therefore first you should take the table upside down then sum :
select * from myTable ;
 order by GLOCField descending ;
 into cursor UpSideDown ;
 nofilter

select *, sum(SumField) as TotSomething ;
 from UpSideDown ;
 group by GLOCField ;
 into cursor mySum
PS: If the record you want to get with same key had something like being max() of that group then you could do that in one SQL.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform