我需要帮助
我有三张表格如下:
customers [ CID , name , address , phone ]
contracts [ ID , CID , TotalPrice , ]
Payment [ ID , CID , pay ]
我想得到客户的姓名,电话号码和 sum(contract .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 ";
答案 0 :(得分: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
中附加带“[]”的保留关键字