如何连接3张桌子?
select *
from tblcustomer as cust
inner join (tblamountdetails as det on det.[CustomerID]=cust.[CustomerID])
inner join (select cash.AccountID, sum(Amount) as [Paid Amount]
from tblcashdetails as cash
group by cash.AccountID) as cash2
on cash2.AccountID=det.AccountID
表格格式:
1) cutomertable:
customerid | customername | Address | phone
1 arun palani 1212112221
2 aaa sssss 123123123
2)Amountdetailtable:
AccountID | customerid | Total amount | Daily Amount
1 1 12000 120
3)cashtable :
AccountID | customerid | amount(given day by day)
1 1 120
1 1 120
最后我想要这样......
customerid | customername |AccountID| totalamount | daily amount | amount(given)
1 arun 1 12000 120 240(this is sum of amount in table 3 where custid=1)