Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Trick?
Message
 
 
À
27/09/2003 12:47:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00832936
Message ID:
00832941
Vues:
16
This message has been marked as the solution to the initial question of the thread.
Tom,

Try
SELECT category, MAX(date) AS maxdate ;
	FROM xx ;
	GROUP BY category ;
	INTO CURSOR crsMaxDate NOFILTER
SELECT xx.category, ;
		md.maxdate, ;
		MAX(IIF(xx.date<md.maxdate, xx.date, {})) AS nextdate ;
	FROM xx ;
	JOIN crsMaxDate md ON md.category = xx.category ;
	GROUP BY xx.category, md.maxdate ;
	INTO CURSOR crsResult NOFILTER
>Using the script below how can I get the MAX() date
>and the second most max date for each category?
>
>That is I want a result (via a SQL Statement) that
>will show the following:
>
>
>category   date        secondmostrecent
>A          01/03/2003  01/02/2003
>B          02/03/2003  02/02/2003
>
>
>
>CREATE CURSOR xx (category c(1), date d)
>INSERT INTO xx VALUES("A", {^2001/01/01})
>INSERT INTO xx VALUES("A", {^2001/01/02})
>INSERT INTO xx VALUES("A", {^2001/01/03})
>INSERT INTO xx VALUES("B", {^2001/02/01})
>INSERT INTO xx VALUES("B", {^2001/02/02})
>INSERT INTO xx VALUES("B", {^2001/02/03})
>
>SELECT category, MAX(date) date FROM xx GROUP BY category
>
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform