I want to get the current sum based on previous data. Exemple:
*******************************************
* Current balance * Total sum *
*******************************************
8500 8500
-500.50 7999.50
380.90 8380.40
-5500 2880.40
I don't have any own code to show because I don't know how to accomplish this, besides using a simple SUM()
(SELECT SUM(data_sum) FROM table ...
).
I have found many similar questions of this but I don't understand the answers (example 1).
Here's my table:
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_user` int(11) DEFAULT NULL,
`id_account` int(11) DEFAULT NULL,
`id_account_to` int(11) DEFAULT NULL,
`id_store` int(11) DEFAULT NULL,
`id_image` int(11) DEFAULT NULL,
`data_name` varchar(45) NOT NULL,
`data_name_short` varchar(45) NOT NULL,
`data_sum` decimal(10,2) DEFAULT NULL,
`data_file` text NOT NULL,
`data_note` text NOT NULL,
`is_transfered` tinyint(4) DEFAULT NULL,
`add_time` tinyint(4) DEFAULT NULL,
`datetime_payed` datetime NOT NULL,
`datetime_added` datetime NOT NULL,
`datetime_edited` datetime NOT NULL
Now to my question: how can I make the SQL query calculate the running total like in the first example, based on the table above?