I am trying to create a running total using Access SQL I have written the following SQL statement but it is not working. My SQL is not good and I am trying to learn could someone help me with it. It would also be nice if I could see it in design view after I write it.
<figure>
<img src='image.jpg'/>
<figcaption>Caption</figcaption>
</figure>
答案 0 :(得分:1)
I am inclined to do this type of calculation using a correlated subquery:
$start = Carbon::now()->startOfMonth();
$end = Carbon::now();
This saves both the SELECT spc.Date, spc.PayeeID, spc.PermCashIn, spc.Year,
(SELECT SUM(sp2.PerCashIn)
FROM SubQrySUMPermCashIN as spc2
WHERE spc2.Date <= sp.Date
) as RunningTotal
FROM SubQrySUMPermCashIN as spc;
and the outer join
. Note that the use of table aliases also makes the query easier to write and to read.
答案 1 :(得分:0)
I don't have Access to test this, but try the code below:
df = df.groupby(['Experiment', 'Step'], sort=False, as_index=False)['value'].aggregate(np.sum)
NB: your SELECT
SubQrySUMPermCashIN.Date
,SubQrySUMPermCashIN.PayeeID
,SubQrySUMPermCashIN.PermCashIn
,SubQrySUMPermCashIN.Year
,Sum(tblTest.PermCashIn) AS RunningTotal
FROM
SubQrySUMPermCashIN
INNER JOIN
SubQrySUMPermCashIN AS tblTest
ON
SubQrySUMPermCashIN.Date >= tblTest.Date
GROUP BY
SubQrySUMPermCashIN.Date
,SubQrySUMPermCashIN.PayeeID
,SubQrySUMPermCashIN.PermCashIn
,SubQrySUMPermCashIN.Year;
was contradicting your WHERE
; amended it so that the JOIN ... ON ...
contains the correct defintion and the ON
is not longer required.