Peter Nordberg
asked on
count and divide query
Hi,
I have a query looking like this:
SELECT dbo.shopCart.product, COUNT(dbo.shopCart.product ID) 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
I have a query looking like this:
SELECT dbo.shopCart.product, COUNT(dbo.shopCart.product
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Peter