Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Last 3 orders from each customer - sql puzzle
Message
 
À
23/09/1999 17:18:51
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00268263
Message ID:
00268274
Vues:
26
>I want to make a file containing the last three orders for each customer.
>
>For example, in TasTraders, I can see all customer orders with:
>
>SELECT Customer.customer_id, Orders.order_id, Orders.order_date;
> FROM tastrade!orders INNER JOIN tastrade!customer ;
> ON Orders.customer_id = Customer.customer_id;
> ORDER BY Customer.customer_id, Orders.order_date DESC
>
>But I want only the first three records for each customer. If I say
>
>SELECT TOP 3 Customer.customer_id, Orders.order_id, Orders.order_date;
> FROM tastrade!orders INNER JOIN tastrade!customer ;
> ON Orders.customer_id = Customer.customer_id;
> ORDER BY Customer.customer_id, Orders.order_date DESC
>
>I get the first three records only, not three for each customer.
>I think this calls for a nested sort. Has anyone devised a way?

Have you tried to GROUP BY customer.customer_id

Wayne
Wayne Myers, MCSD
Senior Consultant
Forte' Incorporated
"The only things you can take to heaven are those which you give away" Author Unknown
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform