Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Vaishu
Posting Yak Master
178 Posts |
Posted - 2008-10-22 : 11:19:33
|
HiBelow is my scenario.. Columns-------------------------------TablesBProdID, URL, SearchTerms,BehaveID - TblBrowsePProdID,SKU - TblProductOrdID,OProdID,QTY,Price - TblOrderTblBrowse -This table log all the hits for the productsTblProduct - This table has all the productsTblOrder - This table has all the order placed onlineBProdID & OProdID contains the product ID from PProdID of TblProduct.I need to calculate How many hits per product, How many times sold that product, if sold what is the total amount of SALES for that product.Exmple: - Hits --Code------NumOfSales-----Amount433 ---AB56TF------20------------£3450322----GH78-OP-----24------------£1960 13----RR5t6Y------32------------£2980I am using the below code without success, please help :SELECT COUNT(B.BProdID) AS Hits, B.URL, B.Searchterms,P.Sku as Code, Count(O.OrdID) As NumOfSales ,Sum(O.Price) AS Amount , Sum(O.QTY) As QTY FROM TblOrder O RIGHT OUTER JOIN TblBrowse B RIGHT OUTER JOIN TblProduct P ON COALESCE(B.BProdID,0) = P.PProdID ON COALESCE(B.BProdID,0) = COALESCE(O.OProdID,0) WHERE B.BehaveID = 2 GROUP BY O.Price,B.BProdID,P.Sku,O.QTY ORDER BY Hits DESC |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-22 : 11:32:31
|
| [code]SELECT b.NoOfHits,p.SKU AS Code,o.NoOfSales,o.TotalPriceFROM tblProduct pINNER JOIN(SELECT OProdID,SUM(Price) AS TotalPrice,SUM(Qty) AS TotalQty,COUNT(OrdID) AS NoOfSales FROM tblOrder GROUP BY OProdID)oON o.OProdID=p.PProdIDINNER JOIN (SELECT BProdID,COUNT(*) AS NoOfHits FROM tblOrder GROUP BY BProdID)bON b.BProdID=p.PProdID[/code] |
 |
|
|
Vaishu
Posting Yak Master
178 Posts |
Posted - 2008-10-23 : 04:29:37
|
HiI changed little bit and works fine. THANKS A LOTquote: Originally posted by visakh16
SELECT b.NoOfHits,p.SKU AS Code,o.NoOfSales,o.TotalPriceFROM tblProduct pINNER JOIN(SELECT OProdID,SUM(Price) AS TotalPrice,SUM(Qty) AS TotalQty,COUNT(OrdID) AS NoOfSales FROM tblOrder GROUP BY OProdID)oON o.OProdID=p.PProdIDINNER JOIN (SELECT BProdID,COUNT(*) AS NoOfHits FROM tblOrder GROUP BY BProdID)bON b.BProdID=p.PProdID
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 04:34:27
|
cheers |
 |
|
|
|
|
|
|
|