Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A SQL challenge
Message
De
10/04/2014 01:44:16
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
A SQL challenge
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Web
Divers
Thread ID:
01598405
Message ID:
01598405
Vues:
93
See the attached image, a partial screen shot for the final answer

Using the AdventureWorks database (and specifically the tables Purchasing.PurchaseOrderHeader and Purchasing.Vendor), we want to write a query that will do the following:

- For orders in 2006, show the first order for each Vendor that gave them a cumulative order $$$ amount of at least $10,000 for the year (of 2006)

- So in the attached image, order 161 for Vendor 1494 for $9,776.2665 gave them a cumulative amount in 2006 of at least $10,000.

- Not all vendors will show. Vendor 1492 does not show because they did not accumulate $10,000 in orders in 2006

From PurchaseOrderHeader, you'll want to use the columns VendorID, PurchaseOrderID, OrderDate, and TotalDue (the dollar amount on the order)
From the Vendor master, you'll want to use the BusinessEntityID (which joins to the VendorID in the POHeader table) and the Vendor Name

A hint....the PO Header table has an Order Date column. You could have two orders on the same day, and perhaps either the first or the second would put the vendor over the magic $10,000 value. For purposes of this example, assume that the lower value for the PurchaseOrderID column is the first of the two orders.

I have a query that produces the result, but curious if anyone wants to give it a shot. My solution is probably not the most optimal, so I'll be happy if someone has a solution that's more efficient.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform