ALTER PROCEDURE GetProducts
@CategoryID INT
AS
SELECT COUNT(tblReview.GroupID) AS ReviewCount,
COUNT(tblComment.GroupID) AS CommentCount,
Product.GroupID,
MAX(Product.ProductID) AS ProductID,
AVG(Product.Price) AS Price,
MAX (Product.Year) AS Year,
MAX (Product.Name) AS Name,
AVG(tblReview.Grade) AS Grade
FROM tblReview, tblComment, Product
WHERE (Product.CategoryID = @CategoryID)
GROUP BY Product.GroupID
HAVING COUNT(distinct Product.GroupID) = 1
這是tabels是什麼樣子的結果:計數問題,當我想從不同勢tabels
**Product** |**tblReview** | **tblComment**
ProductID | ReviewID | CommentID
Name | Description | Description
Year | GroupID | GroupID
Price | Grade |
GroupID
羣ID是name_year一個產品,前Nike_2010的。一種產品可以有不同勢尺寸exampel:
ProductID | Name | Year | Price | Size | GroupID
1 | Nike | 2010 | 50 | 8 | Nike_2010
2 | Nike | 2010 | 50 | 9 | Nike_2010
3 | Nike | 2010 | 50 | 10 | Nike_2010
4 | Adidas| 2009 | 45 | 8 | Adidas_2009
5 | Adidas| 2009 | 45 | 9 | Adidas_2009
6 | Adidas| 2009 | 45 | 10 | Adidas_2009
我沒有得到正確的計數我tblReview和tblComment。如果我將評論添加到耐克大小8,並且我將一個評論添加到耐克大小10,那麼當我列出具有不同GroupID的產品時,我想要2次計數結果。現在我對「評論和評論」也有同樣的看法,兩者都是錯誤的。
我用一個DataList顯示所有與不同勢/唯一的GroupID的產品,我希望它是這樣的:
______________
| |
| Name: Nike |
| Year: 2010 |
| (All Sizes) |
| x Reviews |
| x Comments |
| x AVG Grade |
|______________|
所有Reviewcounts,Commentcounts和所有產品的平均使用相同的組ID,該平均工作很好。
非常感謝!很棒! – Nicklas 2010-05-22 16:29:09