0

我需要帮助

我有如下三个表:

customers [ CID , name , address , phone ] 

contracts [ ID , CID , TotalPrice , ] 

Payment [ ID , CID , pay ] 

我想获取客户的姓名、他的电话号码和 sum(contracts .TotalPrice) - sum(Payment.pay) 的值作为 Remaning

但我很难做到这一点

我用的是microsoft access 2007

我用这个说法

select customers.name , customers.phone , customers.address, (sum( contracts .TotalPrice ) - sum(Payment.pay)) as Remaning from customers  inner join  contracts on customers.CID=contracts.CID  inner join Payment on contracts.CID=Payment.CID ";
4

1 回答 1

1
select customers.CID ,customers.[name] , customers.phone , customers.address, 
(sum( contracts .TotalPrice ) - sum(Payment.pay)) as Remaning 
from customers  inner join  contracts on customers.CID=contracts.CID  
inner join Payment on contracts.CID=Payment.CID GROUP BY customers.CID";

编辑:您需要在 MS Access 中用“[]”括起来保留关键字

于 2013-08-13T16:06:29.097 回答