Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Last 3 orders from each customer - sql puzzle
Message
De
25/09/1999 14:09:06
Cindy Winegarden
Duke University Medical Center
Durham, Caroline du Nord, États-Unis
 
 
À
25/09/1999 13:55:37
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:
00268973
Vues:
34
>Actually, I glad you replied because now I don't have to go searching for this thread. I guess I was brain dead the other day and missed the obvious answer.
>
>SELECT *
>FROM orders INNER JOIN ordlines
> orders.orderid = ordlines.orderid
>WHERE orders.orderid IN (
> SELECT TOP 3 orderid
> FROM orders
> ORDER BY orderdate DESC)
>
>-Mike

Mike,

The followint (Use the VFP sample data) doesn't work:

SELECT orders.*, orditems.* ;
FROM orders INNER JOIN orditems ON orders.order_id = orditems.order_id ;
WHERE orditems.lineno IN ;
(SELECT TOP 3 lineno FROM orditems ORDER BY quantity DESC)

This is exactly why the question was originally posted, you can't put a SELECT TOP x in a subquery. I wrestled with this last winter, and settled on the loop-and-accumulate solution to get the top x in each of my categories.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform