MS Access和SQL查询

时间:2017-05-15 21:36:16

标签: sql ms-access ms-access-2010

我试图报告我的查询,但我得到了

  

JOIN操作中的语法错误

有关如何正确设置括号的任何建议吗?

select 
    v.VendorID, v.Name,
    CCur(Format(sum(p.ListPrice * (1 - sp.DiscountPercent) * od.OrderQuantity), "0.00")) as Sales,
    sum(p.ListPrice-p.Cost) as Profit,
    sum(od.OrderQuantity) as Quantitiy, 
    sum(sp.DiscountPercent) as Discounts
from 
    ((((vendor v
join 
    product p on v.VendorID = p.VendorID)
join 
    OrderDetail od on p.ProductID = od.ProductID)
join 
    OrderHeader oh on od.OrderID = oh.OrderID)
join 
    SalesPromotion sp on od.SalesPromotionID = sp.SalesPromotionID)
where 
    year(oh.OrderDate) = 2014
group by 
    v.VendorID, v.Name
order by 
    Sales desc

谢谢!

1 个答案:

答案 0 :(得分:1)

这样可以解决错误吗?

FROM (((Vendor v
JOIN Product p ON v.VendorID = p.VendorID)
JOIN OrderDetail od ON p.ProductID = od.ProductID)
JOIN OrderHeader oh ON od.OrderID = oh.OrderID)
JOIN SalesPromotion sp ON od.SalesPromotionID = sp.SalesPromotionID