Solved

T-sql

Posted on 2011-09-27
3
412 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

760 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

22 Experts available now in Live!

Get 1:1 Help Now