Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Last 5 records in SQL Select
Message
From
30/10/2007 07:02:05
Erick Miranda
Formata Data Business - Grupo Linx
Contagem, Brazil
 
 
To
30/10/2007 04:21:53
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01264947
Message ID:
01264954
Views:
11
Hi Agnes,

>Hi All,
>
>I have a table that holds a time tabes status per customer.
>
>I would like to create an SELCT SQL that gives me the 5 most recent records per customer
>
>like
>
>customer, date,value
>A,2007-01-01,1
>A,2007-01-02,2
>A,2007-01-03,3
>A,2007-01-04,4
>A,2007-01-05,5
>A,2007-01-06,6
>A,2007-01-07,7
>A,2007-01-08,8
>B,2007-01-02,2
>B,2007-01-03,3
>B,2007-01-04,4
>B,2007-01-05,5
>B,2007-01-16,6
>B,2007-01-17,7
>B,2007-01-18,8
>C,2007-01-17,7
>C,2007-01-18,8
>
>Result set:
>A,2007-01-04,4
>A,2007-01-05,5
>A,2007-01-06,6
>A,2007-01-07,7
>A,2007-01-08,8
>B,2007-01-03,3
>B,2007-01-04,4
>B,2007-01-05,5
>B,2007-01-16,6
>B,2007-01-17,7
>C,2007-01-17,7
>C,2007-01-18,8
>
>
>Any idea how to achive this?
>
>Agnes

Wouldn't be value's customer B from 4 until 8? (you putted 3 until 7)
If your answer is yes. Try:
SELECT mA.*;
	FROM myTable mA;
		, (SELECT customer, MAX(value) maxValue;
				FROM myTable;
				GROUP BY customer;
			) mB;
	WHERE 	mA.customer = mB.customer;
		AND mA.value > mB.maxValue - 5;
	ORDER BY mA.customer, mA.value
Good luck!
Erick
Força Sempre!
Strength Always!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform