Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Aggregate Field..
Message
From
04/06/2001 01:26:52
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Aggregate Field..
Miscellaneous
Thread ID:
00514417
Message ID:
00514417
Views:
39
Hi All,

In case of using GROUP BY in SQL-SELECT, The Last record of criteria
is selected for each group though there is no aggregate field.
But I heard it's unreliable. Here is my code.

** because records are not inserted in the order of date,
** select all records from table sorted by desired order
** before real SQL.
** Though mytable has INDEX for custid+dtos(date) and I open
** with proper order with another alias, SQL only tells phisically
** saved last record.

lcAlias=SYS(2015)
select custid,date,debt,custid+dtos(date);
FROM myTable ;
where date < someday;
into cursor (lcAlias) order by 4

** get the last debt of each custid
select custid,MAX(date),debt from (lcAlias);
GROUP BY CUSTID into cursor myCursor
** select custid,date,debt from (lcAlias);
** GROUP BY CUSTID into cursor myCursor

Though I can have the last debt and date per custid correctly,
I'm not so sure My way is correct.
And in ther 2nd-Query, Regardless of using MAX() I have the
same result. I need an advice what is the most reliable way
to get the last record of some specific order.

Any comments would be appreciated.

RGDS
HK.Lee
MCP
Next
Reply
Map
View

Click here to load this message in the networking platform