View previous topic :: View next topic |
Author |
Message |
yellowhat Guru
Joined: 10 Sep 2008 Posts: 528
|
Posted: Sun Oct 09, 2011 9:41 pm Post subject: [Solved] Libreoffice Base: Cumulative sum |
|
|
Hi all, I am new to libreoffice base, so I decided to ask you an advice. I want to create, in a query, a new column with cumulative sum such as:
A SUM
1 1
2 3
3 7
Could you help me?
Thanks
Last edited by yellowhat on Mon Oct 17, 2011 7:23 pm; edited 1 time in total |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10589 Location: Somewhere over Atlanta, Georgia
|
Posted: Sun Oct 09, 2011 9:47 pm Post subject: |
|
|
Moved from Other Things Gentoo to Desktop Environments. Not about Gentoo so it fits better here (I think).
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
yellowhat Guru
Joined: 10 Sep 2008 Posts: 528
|
Posted: Wed Oct 12, 2011 6:21 pm Post subject: |
|
|
Any ideas? |
|
Back to top |
|
|
wizulis n00b
Joined: 07 Nov 2010 Posts: 46
|
Posted: Thu Oct 13, 2011 6:19 am Post subject: |
|
|
If I understand correctly what you want, then it is pretty easy:
Assuming that the
"A" is in cell A1 and "1" is in cell A2 and "2" is in cell "A3" just write in B2
=sum($A$2:A2)
Then push enter, select the cell again and pull it down by the square in the right bottom corner of the cell. |
|
Back to top |
|
|
yellowhat Guru
Joined: 10 Sep 2008 Posts: 528
|
Posted: Thu Oct 13, 2011 6:26 am Post subject: |
|
|
Thanks for reply but my question was about creating a query in libreoffice base not calc. |
|
Back to top |
|
|
yellowhat Guru
Joined: 10 Sep 2008 Posts: 528
|
Posted: Sat Oct 15, 2011 3:07 pm Post subject: |
|
|
Anyone know how to write this query in sql for libreoffice base? |
|
Back to top |
|
|
yellowhat Guru
Joined: 10 Sep 2008 Posts: 528
|
Posted: Sat Oct 15, 2011 4:32 pm Post subject: |
|
|
This is quite good:
SELECT "ID", "Quantita", (SELECT SUM("Quantita") from "Tabella1" WHERE "ID" <= "ID") AS "Running Total"
from "Tabella1"
But as result I get:
1 10
2 10
3 10
4 10
It is not progressive but something must be changed here: WHERE "ID" <= "ID" |
|
Back to top |
|
|
yellowhat Guru
Joined: 10 Sep 2008 Posts: 528
|
Posted: Mon Oct 17, 2011 7:23 pm Post subject: |
|
|
This works perfectly
Code: | SELECT
"A"."ID",
"A"."Quantita",
( SELECT SUM("B"."Quantita")
From "Tabella1" as "B"
WHERE "B"."ID" <= "A"."ID") AS "Running Total"
From "Tabella1" as "A" |
|
|
Back to top |
|
|
|