Link to home
Start Free TrialLog in
Avatar of Peter Nordberg
Peter NordbergFlag for Sweden

asked on

count and divide query

Hi,
I have a query looking like this:
      SELECT        dbo.shopCart.product, COUNT(dbo.shopCart.productID) AS Antal
      FROM            dbo.[Order] INNER JOIN
                                           dbo.shopCart ON dbo.[Order].orderID = dbo.shopCart.orderID INNER JOIN
                                           dbo.[Order] AS o ON dbo.[Order].orderID = o.orderID
      WHERE        (dbo.[Order].customerID IS NOT NULL)
      GROUP BY dbo.shopCart.product, dbo.shopCart.productID
      ORDER BY antal DESC
--------------------------------------------------
That conts how many products that has been sold per productID. I would like to add a field that counts the percentage rate of the row productIID as compared to the whole sale (all productIDs).

I would like my result to look like this:
Product               Antal           %
A product           1000           10%             (the total sale is 10 0000 products)

Is there a way to achieve this?

Thanks for help!

Peter
ASKER CERTIFIED SOLUTION
Avatar of tigin44
tigin44
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Peter Nordberg

ASKER

Thanks for help!

Peter