2014-07-17 63 views
-3

您好,我有這些客戶都在不同的時間有記錄賺來的錢從我們公司客戶的表都是這樣的總和:中如何讓每個人單獨

ID  Amount Payable 

1000 340.00 
1001 223.00 
1000 122.00 
1000 344.00 
1001 155.00 

我當前的查詢正在總和所有的表,但我想每個ID的總和不是全部。

這裏是我的查詢:

SELECT 
    remoteemployees.RemoteEmployeeID, 
     remoteemployees.Bank, 
     remoteemployees.BeneficiaryName, 
     remoteemployees.AccountNumber, 
     SUM(transactions.AmountPayable) As TotalPayment, 
     transactions.RemoteEmployeeID 

     FROM remoteemployees, transactions 

    WHERE 
     remoteemployees.RemoteEmployeeID = transactions.RemoteEmployeeID 

回答

-1

使用組。請按照此link瞭解更多詳情和教程

SELECT 
remoteemployees.RemoteEmployeeID, 
    remoteemployees.Bank, 
    remoteemployees.BeneficiaryName, 
    remoteemployees.AccountNumber, 
    SUM(transactions.AmountPayable) As TotalPayment, 
    transactions.RemoteEmployeeID 

    FROM remoteemployees, transactions 

WHERE 


    remoteemployees.RemoteEmployeeID = transactions.RemoteEmployeeID 
    group by remoteemployees.RemoteEmployeeID 
-2

試試這個:

SELECT 
remoteemployees.RemoteEmployeeID, 
    remoteemployees.Bank, 
    remoteemployees.BeneficiaryName, 
    remoteemployees.AccountNumber, 
    SUM(transactions.AmountPayable) As TotalPayment, 
    transactions.RemoteEmployeeID 

    FROM remoteemployees, transactions 

WHERE 


    remoteemployees.RemoteEmployeeID = transactions.RemoteEmployeeID 
    group by remoteemployees.RemoteEmployeeID, 
+0

Y你有沒有低估這個?你能指出問題嗎? – Torrezzzz

-2

試試這個: - BY子句

SELECT remoteemployees.RemoteEmployeeID, 
     remoteemployees.Bank, 
     remoteemployees.BeneficiaryName, 
     remoteemployees.AccountNumber, 
     SUM(transactions.AmountPayable) As TotalPayment, 
     transactions.RemoteEmployeeID 
FROM remoteemployees INNER JOIN transactions 
ON remoteemployees.RemoteEmployeeID = transactions.RemoteEmployeeID 
GROUP BY transactions.RemoteEmployeeID; 
相關問題