Sql query - sum up things

Hello all,
I have this query =>
SELECT
  Product.ProductID AS [Product ProductID]
  ,Product.CatalogNum
  ,Product.ProductName
  ,Customer.CustomerName
  ,[Order].Quantity
  ,[Order].Refund
  ,[Order].Price
  ,[Order].ProductID AS [Order ProductID]
  ,Product.DisplayOnReport
FROM
  [Order]
  INNER JOIN Customer
    ON Customer.CustomerID = [Order].CustomerID
  INNER JOIN Product
    ON Product.ProductID = [Order].ProductID
    Where Customer.CustomerID = @CI ORDER BY Product.CatalogNum

The same customer probably ordered the same product more than once, I'd like to get 1 row per product (1 row that sums up all the Quantity from other rows).
I need that for a report I'm building.

thank you
LVL 2
kulpemAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
Hi there,
here you go
SELECT
  Product.ProductID AS [Product ProductID]
  ,Product.CatalogNum
  ,Product.ProductName
  ,Customer.CustomerName -- one customer, works if all the same customer
  ,SumQty=Sum([Order].Quantity)
--  ,[Order].Refund
--  ,[Order].Price
--  ,[Order].ProductID AS [Order ProductID]
  ,Product.DisplayOnReport
FROM
  [Order]
  INNER JOIN Customer
    ON Customer.CustomerID = [Order].CustomerID
  INNER JOIN Product
    ON Product.ProductID = [Order].ProductID
    Where Customer.CustomerID = @CI
--ORDER BY Product.CatalogNum
GROUP BY Product.ProductID, Product.CatalogNum, Product.ProductName, Product.DisplayOnReport,
Customer.CustomerName

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kulpemAuthor Commented:
That worled for me



SELECT
  Product.ProductID AS [Product ProductID]
  ,Product.CatalogNum
  ,Product.ProductName
  ,Customer.CustomerName -- one customer, works if all the same customer
  ,SumQty=Sum([Order].Quantity)
,SumRef=Sum([Order].Refund)
,[Order].Price

  ,Product.DisplayOnReport
FROM
  [Order]
  INNER JOIN Customer
    ON Customer.CustomerID = [Order].CustomerID
  INNER JOIN Product
    ON Product.ProductID = [Order].ProductID
    Where Customer.CustomerID = 319
--ORDER BY Product.CatalogNum
GROUP BY Product.ProductID, Product.CatalogNum, Product.ProductName, Product.DisplayOnReport,
Customer.CustomerName, [Order].Price

Open in new window

0
kulpemAuthor Commented:
thank you
0
kulpemAuthor Commented:
Well it not working that good I forgot the mention the dates
I need something like that =>
using Date range. but this query outs me back to square 1, I get each order in one row, instead of summing up Quntity and Refund
SELECT
  Product.ProductID AS [Product ProductID]
  ,Product.CatalogNum
  ,Product.ProductName
  ,Customer.CustomerName 
  ,SumQty=Sum([Order].Quantity)
  ,SumRef=Sum([Order].Refund)
  ,[Order].Price
  ,[Order].Date
  ,Product.DisplayOnReport
FROM
  [Order]
  INNER JOIN Customer
    ON Customer.CustomerID = [Order].CustomerID
  INNER JOIN Product
    ON Product.ProductID = [Order].ProductID
    Where Customer.CustomerID = 319 AND [Order].Date BETWEEN '01-01-2000' AND '01-01-2030'
	GROUP BY Product.ProductID, Product.CatalogNum, Product.ProductName, Product.DisplayOnReport,
	Customer.CustomerName, [Order].Price, [Order].Date

Open in new window

0
kulpemAuthor Commented:
Sorry my mistake.
I better goto sleep soon.
verything is cool I got it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.