Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting first 2 dates of each category.
Message
From
25/08/2004 15:40:47
Randy Riegel
Zimish Contracting
Ohio, United States
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00936359
Message ID:
00936399
Views:
24
I forgot to mention that the "first 2" is just an example. I may want to get the first 3, 4, 5, 10, 50, 100, etc. entries for each category. I solve the problem by creating a temp copy of the file, adding a column to it called entry_no, then scanning through the file and numbering each entry until the cat changes then reset the counter so that each cat has a entry_no from 1 to ? that I can then "select * where entry_no < X".

Randy



>Not elegant, but works:
>
>
>SELECT cat, MAX(_date) _date FROM yy GROUP BY 1 INTO CURSOR tmp1
>INDEX ON cat+DTOC(_date) TAG _1
>
>SELECT cat,MAX(_date) FROM yy GROUP BY 1 ;
>UNION;
>SELECT cat,MAX(_date) FROM yy ;
>	WHERE NOT INDEXSEEK(yy.cat+DTOC(yy._date),.f.,"tmp1","_1") GROUP BY 1 ;
>ORDER BY 1,2
>
>
>
>>I have a table layed out similar to the follownig:
>>
>>
>>cat1     date1     amount
>>cat1     date2     amount
>>cat1     date3     amount
>>cat1     date4     amount
>>cat2     date1     amount
>>cat2     date2     amount
>>cat3     date1     amount
>>cat3     date2     amount
>>cat3     date3     amount
>>
>>
>>I want to get the oldest 2 dates from each category into a table. I want my table to look like the following:
>>
>>
>>cat1     date1     amount
>>cat1     date2     amount
>>cat2     date1     amount
>>cat2     date2     amount
>>cat3     date1     amount
>>cat3     date2     amount
>>
>>
>>Any easy way to do this with a select that I am overlooking?
Previous
Reply
Map
View

Click here to load this message in the networking platform