我正在编写一个脚本,其中拍卖应该能够包含多种产品。一个产品有一个正常价格,它是对拍卖中所有产品的总和,然后作为拍卖“包”正常价格返回。
我的问题是,我的测试拍卖的正常价格为 150 美元,但查询返回 300 美元,这意味着我在某处犯了错误。我整晚都在试图找到解决方案 - 但没有成功。有人有线索吗?
SELECT 
    a.AuctionName as A_name, 
    c.CategoryName as C_name, 
    a.AuctionEndDate as A_enddate, 
    a.AuctionOfferPrice as A_price, 
    SUM(p.ProductPrice) as A_normalprice, 
    s.StoreName as S_name 
FROM A_Auctions a 
RIGHT JOIN 
    A_Categories c 
    ON c.CategoryID = :category_id 
INNER JOIN 
    P_ProductsAuctions ppa 
    ON ppa.Auct_AuctionID = a.AuctionID 
RIGHT JOIN 
    P_Products p 
    ON p.ProductID = ppa.Prod_ProductID 
RIGHT JOIN 
    P_Attributes pa 
    ON pa.Cate_CategoryID = c.CategoryID 
RIGHT JOIN 
    P_AttributeValues pav 
    ON pa.AttributeID = pav.Attr_AttributeID 
LEFT JOIN 
    S_Stores s ON a.Stor_StoreID = s.StoreID 
WHERE 
    a.Cate_CategoryID = c.CategoryID 
    AND ((pa.InternationalName = 'param1' AND pav.AttributeValue = 'value1') OR (pa.InternationalName = 'param1' AND pav.AttributeValue = 'value2')) 
    AND ((pa.InternationalName = 'param2' AND pav.AttributeValue = 'value1') OR (pa.InternationalName = 'param1' AND pav.AttributeValue = 'value2'))
GROUP BY 
    p.ProductID, a.AuctionID, pa.AttributeID ORDER BY a.AuctionID DESC 
LIMIT 0,20
这是我的表结构:
A_拍卖:
AuctionID   int(15)         
AuctionName varchar(256)        
AuctionDescription  text        
AuctionPicture  text        
AuctionOfferPrice   decimal(15,2)           
AuctionMinimumPrice decimal(15,2)           
AuctionStartDate    datetime            
AuctionEndDate  datetime            
AuctionTimeInterval time            
AuctionNextInterval datetime            
AuctionPercentageChange decimal(5,2)            
Cate_CategoryID int(15)         
Prod_ProductID  int(15)         
Stor_StoreID    int(15)         
StUs_StoreUserID    int(15)         
date_added  datetime
P_产品:
ProductID   int(15)         
ProductName varchar(256)        
ProductDescription  text        
ProductPictureLink  longtext    
ProductPrice    decimal(25,2)           
ProductStatus   int(3)          
ProductGroupID  int(15)         
Cate_CategoryID int(15)         
StUs_UserID int(15)         
added_date  datetime
P_ProductsAuctions(存储拍卖和产品之间的 1:Many 关系):
Auct_AuctionID  int(15)         
Prod_ProductID  int(15) 
P_Attributes(产品不同变体的表):
AttributeID int(15)         
Auct_AuctionID  int(15)         
Cate_CategoryID int(15)         
AttributeName   varchar(256)        
InternationalName   varchar(256)
编辑: - 问题似乎与 P_Attributes 和 P_AttributeValues 中的参数有关,因为当我向查询中添加 1 个参数时,价格要高 150 美元 - 所以 300 美元有 1 个参数,450 美元有 2 个参数,600 美元有 3 个参数和很快...
编辑2:
在这里找到一个 SQLfiddle:http ://sqlfiddle.com/#!2/d223f/1
编辑 3:
我的输出应该是:
A_NAME -> 测试
C_NAME -> 测试
A_ENDDATE -> 2012 年 9 月 9 日 22:00:00-0400
A_PRICE -> 250
A_NORMALPRICE -> 150
S_NAME ->(空)
提前致谢,
登劳