获取所有最后的交易并总结所有并在datagridview中查看

时间:2015-05-26 11:20:47

标签: sql vb.net datagridview

我已经为我的问题搜索了解决方案,但从我读过的内容来看,我对如何将其纳入我的程序感到困惑。 我有一张桌子。我只想获得每个员工的所有最后交易并总结所有这些交易。例如:

|EmployeeID| |Date|             |Amount|
   101        5/5/2014            168.00
   102        5/5/2014            173.00
   101        5/10/2014           300.00
   102        5/11/2014           100.00
   103        5/11/2014           150.00

我需要获得此值:Total: 550.00 我的数据库是MS Access 这是我的代码:

SELECT SUM(SalesmanAcct) As total 
FROM (SELECT LAST(TransactionDate) FROM SalesmanLedger GROUP BY EmployeeID)

2 个答案:

答案 0 :(得分:0)

我认为你需要Amount

SELECT SUM(Amount) As total 
FROM (SELECT LAST(Amount) FROM SalesmanLedger GROUP BY EmployeeID) as a

答案 1 :(得分:0)

您可以尝试以下查询: -

SELECT SUM(AMOUNT)
FROM TABLE1 WHERE in_DATE IN (SELECT to_DATE 
                              FROM (SELECT EmployeeID, MAX(in_Date) AS to_DATE
                                    FROM TABLE1
                                    GROUP BY EmployeeID) TAB1
                             )