Greetings. Faced a problem, there is a table with transactions, and in it a column with timestump. It is necessary to sum up the account balance on each day in a certain time interval.

As an option, consider the execution of the request for each of the days, typing the remainder by summing up all previous transactions. But I do not think that this method is correct. What solution can you tell?

Data demo: http://sqlfiddle.com/#!9/821821

  • one
    It is not clear what you need. What kind of transaction, what information other than the date it is stored. Do you think the balance on the account or the amount of transactions? The amount of transactions is elementary. For balances, the base structure should be somewhat more complicated, closer to the accounting turnovers, where for each day / operation there is a starting and ending balance. Then it is not necessary to count anything - take it ready. - Sergey
  • Here the day before yesterday I transferred a request to MySQL that showed the movement of money and the balance at the beginning and end of the day
  • @Sergey sqlfiddle.com/#!9/821821 - Happy_Cougar
  • What can I say. Yes, with such a structure, you have no other option how to sum up all the transactions every time, starting with the very first and up to a given date. And so for each day of the period. I do not remember that the possibility of an "iterative" account was provided in sql. This of course can be done at the application level. - Sergey
  • @Sergey What do you think, is it possible to somehow improve the structure? - Happy_Cougar

0