Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Last 5 records in SQL Select
Message
De
30/10/2007 07:02:05
Erick Miranda
Formata Data Business - Grupo Linx
Contagem, Brésil
 
 
À
30/10/2007 04:21:53
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Divers
Thread ID:
01264947
Message ID:
01264954
Vues:
12
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!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform