Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting first 2 dates of each category.
Message
 
 
À
25/08/2004 13:02:24
Randy Riegel
Zimish Contracting
Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00936359
Message ID:
00936460
Vues:
21
Randy,

Try
* Assign seq # to each record
SELECT cat, date, amount, 0000000000 AS rn ;
	FROM mytable ;
	ORDER BY cat, date ;
	INTO CURSOR crsTest01 READWRITE
REPLACE ALL rn WITH RECNO()
* Select nn records in each group
lnMrn = 2  && 2 rec's
SELECT cat, date, amount ;
	FROM crsTest01 t11 ;
	WHERE rn < ( SELECT MIN(rn+lnMrn) FROM crsTest01 t12 ;
			WHERE t12.cat = t11.cat)
>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?
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform