Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting dates
Message
From
28/11/2006 11:20:41
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01172906
Message ID:
01172964
Views:
15
Hi Sergey:

Awesome! I'll let you know when I've tested it.

Thanks,

Yossi

>
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform