Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Trick?
Message
 
 
To
27/09/2003 12:47:00
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00832936
Message ID:
00832941
Views:
15
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--
Previous
Reply
Map
View

Click here to load this message in the networking platform