0

是否可以连接两个表,过滤数据并在 MS 访问中采用聚合功能?我有两张桌子

Inv_details:invnum,itmcde,qnt,price  
Inv_summary:invnum,date,total  

我需要加入这些表并使用日期范围过滤它们,并通过 itmcde 获得 qnt 和价格订单的总和。

我尝试过这样的事情。

SELECT inv.itmcde,SUM(inv.qnt),SUM(inv.price) FROM (SELECT inv_s.invnum,inv_s.date,inv_d.itmcde,inv_d.total FROM Inv_summary as inv_s INNER JOIN Invoice_details as inv_d ON inv_d.invnum =inv_s.invNum WHERE inv_s.date BETWEEN  #3/4/2013# And #5/16/2013# ) as inv ORDER BY inv.itmcde

但这不起作用。

4

1 回答 1

0

尝试

SELECT d.itmcde,
       SUM(d.qnt) AS qnt,
       SUM(d.price) AS price
  FROM Inv_summary s INNER JOIN Inv_details d 
    ON d.invnum = s.invnum 
 WHERE s.date BETWEEN #3/4/2013# AND #5/16/2013# 
 GROUP BY d.itmcde
 ORDER BY d.itmcde

SQLFiddle 虽然这个小提琴适用于 SQL Server,但同样的一般规则应该适用于 MS Access

于 2013-05-21T05:08:18.777 回答