-
T-sql
how I can write query which can write all the coloumns who ordered max quantity
-
Do you have any sample data and what you like to see?
-
Originally Posted by rmiao
Do you have any sample data and what you like to see?
hi rmiao I have a table Name: Order Details
coloumn: orderid, productid, unitprice, quantity, discount
i need all the coloumns to be printed which corresponds to max quantity
-
You need to be a little clearer about what you want, and it would help to provide actual data. However, I'm going to take a guess at what you want:
SELECT * FROM OrderDetails
WHERE quantity = (SELECT MAX(quantity) FROM OrderDetails)
Or, for example, to see all the data corresponding to each OrderId's max quantity:
SELECT * FROM OrderDetails AS A
JOIN (SELECT OrderId, MAX(quantity) AS MaxQuantity FROM OrderDetails GROUP BY OrderID) AS B
ON A.OrderId = B.OrderId AND A.quantity = B.MaxQuantity
etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|