Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting dates
Message
 
 
À
28/11/2006 08:28:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01172906
Message ID:
01172949
Vues:
11
SELECT ;
		SaleDateLast, SPlast, SQlast, ;
		SaleDatePrev, SPprev, SQprev, ;
		SaleDateRest, SPrest, SQrest ;
FROM ( ;
		SELECT 1 AS pk, SaleDate AS SaleDateLast, SUM(pp) AS SPlast, SUM(qq) AS SQlast ;
			FROM mytable ;
			WHERE SaleDate =(SELECT MAX(SaleDate) FROM mytable) ;
			GROUP BY 1,2 ;
		) ld ;
	JOIN ( ;
		SELECT 1 AS pk, SaleDate AS SaleDatePrev, SUM(pp) AS SPprev, SUM(qq) AS SQprev ;
		FROM mytable ;
		WHERE SaleDate =(SELECT MAX(SaleDate) FROM mytable ;
			WHERE SaleDate < (SELECT MAX(SaleDate) FROM mytable)) ;
		GROUP BY 1,2 ;
		) pd ON ld.pk = pd.pk ;
	JOIN ( ;
		SELECT 1 AS pk, {} AS SaleDateRest, SUM(pp) AS SPrest, SUM(qq) AS SQrest ;
		FROM mytable ;
		WHERE SaleDate < (SELECT MAX(SaleDate) FROM mytable ;
			WHERE SaleDate < (SELECT MAX(SaleDate) FROM mytable)) ;
		GROUP BY 1,2 ;
		) rd ON rd.pk = pd.pk
>
>Consider the following data:
>
>
>Sale Date   P         Q
>1/4/06      9         3
>2/4/06      2         7
>2/4/06      3         8
>2/4/06      6         6
>3/4/06      1         5
>5/4/06      4         2
>5/4/06      5         9
>
>
>I want to construct a select statement that will return the following:
>
>
>latest_date  P_lt  q_lt  date-1  p-1  q-1  date-rest  p-rest  q-rest
>5/4/06       9     11    3/4/06  1    5    {}         20      24
>
>
>In other words, I want to get a total of products sold on the latest date, whatever that is; products sold on the date before the latest date, whatever that is; and products sold on all the other prior dates.
>
>Can this be done?
>
>Thanks,
>
>Yossi
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform