Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

T-sql

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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 …

807 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