Forum Moderators: open

Message Too Old, No Replies

Problems with a query

How to write a query for a cumulative sum

         

dbarasuk

12:36 am on Feb 29, 2008 (gmt 0)

10+ Year Member



Hello. I was recently following a tutorial on how to write a query that produces a cumulative sum of my daily expenses.

In fact the table containing my daily expenses is called "expenses". I tried to write a query like this for that issue:

I used a self-join like this:

SELECT t1.date As date, DAYNAME(t1.date) As 'Day Name', t1.amount, TRUNCATE(SUM(t2.amount), 2) As Cumulative_expense FROM expenses as t1, expenses as t2 WHERE t1.date >= t2.date GROUP BY t1.date;

In the book, I recentely followed this query produced a cumulative expense amount but fails to work for me. Can somebody point me into the right correction?

Kind regards,
Darius B.

syber

10:11 pm on Mar 2, 2008 (gmt 0)

10+ Year Member



Why do you need a self-join?