Solved

T-sql

Posted on 2011-09-27
3
414 Views
Last Modified: 2013-11-29
Hello:
Hello:
I really need help on solving the following problems.  I appreciate any input.
Please  refer to schema in the attached file.
Customer with the highest order amount on orders with 5 or more different items
see attached

Get Items with Qty greater than 10 per order.  Select OrderID, OrderDate, CategoryName, ItemName  and Item Qty.


Get-Customer.xls
0
Comment
Question by:gloriagalvez
  • 2
3 Comments
 
LVL 9

Expert Comment

by:edlunad
ID: 36713837
try this for the items with order qty greater than 10..

Select O.OrderID, O.OrderDate, C.CategoryName, I.ItemName, OD.Qty
from [Order] O inner join OrderDetail OD on O.OrderId=OD.OrderId
inner join Item I on OD.ItemID=I.ItemId
inner join Category C on I.CategoryID=C.CategoryID
inner join (SELECT OrderId, sum(OD.Qty) AS TQty
            FROM   OrderDetail
            GROUP BY OrderId) AS OD2 ON OD.OrderId = OD2.OrderId
where  OD2.TQty>10

Open in new window

0
 
LVL 9

Accepted Solution

by:
edlunad earned 500 total points
ID: 36713885
this will be for the highest order amount ...

Select top 1 C.CustomerName, max(O.Amount) as MaxAmount
from [Order] O inner join OrderDetail OD on O.OrderId=OD.OrderId
inner join Customer C on O.CustomerID=C.CustomerID
inner join (SELECT OrderId, COUNT(DISTINCT ItemId) AS TItems
            FROM   OrderDetail
            GROUP BY OrderId) AS OD2 ON OD.OrderId = OD2.OrderId
where  OD2.TItems>5
group by C.CustomerName
order by max(O.Amount) desc

Open in new window

0
 

Author Closing Comment

by:gloriagalvez
ID: 36714288
I test it and it worked like a charm thank you:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now