Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Last 3 orders from each customer - sql puzzle
Message
 
To
29/09/1999 17:06:03
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00268263
Message ID:
00271059
Views:
35
>Using that example, here's the last three orders for each Customer:
>
>SELECT C.customer_id, O1.order_id, O1.order_date ;
> FROM tastrade!Customer C, tastrade!orders O1, tastrade!orders O2 ;
> WHERE C.customer_id = O1.Customer_id AND C.Customer_id = O2.Customer_id ;
> AND DTOS(O1.order_date) + O1.order_id <= DTOS(O2.Order_date) + O2.Order_id ;
> INTO CURSOR Result ;
> GROUP by C.Customer_id, o1.order_date, O1.Order_id ;
> HAVING COUNT(*) <= 3 ;
> ORDER BY O1.customer_id, O1.Order_date DESC

This is a great enhancement to looping through all your customers. Great job!

__Stephen
Previous
Reply
Map
View

Click here to load this message in the networking platform