Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get max() record?
Message
From
16/01/2004 06:28:04
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
16/01/2004 05:53:36
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00867397
Message ID:
00867403
Views:
17
John,

I feel not happy with that but for the moment it should work:
SELECT;
 Cur1.SalesNo,;
 Cur1.SalesDate,;
 Cur1.Amount;
 FROM Sales AS Cur1;
 INTO CURSOR csrMax;
 WHERE DTOC(Cur1.SalesDate)+TRANSFORM(Cur1.Amount) IN(;
 SELECT DTOC(Cur2.SalesDate)+TRANSFORM(MAX(Cur2.Amount));
 FROM Sales AS Cur2;
 GROUP BY Cur2.SalesDate)
if you don't like this way you may do the two step solution what do the same:
SELECT;
 Cur1.SalesDate,;
 MAX(Cur1.Amount) AS nMax;
 FROM Sales AS Cur1;
 INTO CURSOR curHelp;
 GROUP BY Cur1.SalesDate

SELECT;
 Cur1.SalesNo,;
 Cur1.SalesDate,;
 Cur1.Amount;
 FROM Sales AS Cur1;
 INNER JOIN curHelp AS cur2;
 ON Cur1.SalesDate=curHelp.SalesDate;
 AND Cur1.Amount=curHelp.nMax;
 INTO CURSOR csrMax

USE IN curHelp
HTH
Agnes
>Hi,
>I would like to get largest sales amount records for each day. I use the following SQL, it return correct largest sales amount field value, but always last salesno. Any ideas?
>
>
>SELECT SalesNo, SalesDate, MAX(Amount) AS MaxAmount ;
>FROM Sales ;
>GROUP BY 1, 2 ;
>INTO CURSOR csrMax
>
>Data:
>SalesNo     SalesDate         Amount
>A00001      01/01/2003        100
>A00002      01/01/2003        200
>A00003      02/01/2003        100
>A00004      01/01/2003        100
>
>Expected Result:
>A00002      01/01/2003        200
>A00003      02/01/2003        100
>
>Wrong Result returned by SQL above
>A00004      01/01/2003        100
>A00003      02/01/2003        100
>
>
>
>Please advise
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Reply
Map
View

Click here to load this message in the networking platform