Query to find the products and the total price of the each product of a customer

I have a table with the below columns: Customer_Id, Product_Id, Product_Name, Unit_Price, Quantity

I need to find the number of distinct products the customer has purchased and the total cost of the products (which is Unit_Price * quantity). I should get the below 3 columns as the result:

Customer_Id Product_Id Total_Price

more ▼

asked May 21, 2012 at 03:15 AM in Default

avatar image

0 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

you can use SUM Product_Id and GROUP BY Product_Id to find a total amount of product and than multiply with Unit_price, that's all you have to do.

more ▼

answered May 21, 2012 at 08:52 AM

avatar image

323 24 26 31

But I also need the customer_Id column. When I use "group by", I cannot select customer_Id as a column. Please help...

May 21, 2012 at 11:56 AM Shanthi

Yes you can, but you have to GROUP BY also customer_Id

May 21, 2012 at 12:43 PM Gogolo
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: May 21, 2012 at 03:15 AM

Seen: 655 times

Last Updated: May 21, 2012 at 01:20 PM

Copyright 2018 Redgate Software. Privacy Policy