# How to solve this Sum Query Mentor - Bandi

Posted by Jayakumars under ASP.NET AJAX on 5/4/2015 | Points: 10 | Views : 366 | Status : [Member] [MVP] | Replies : 3
hi

how to row wise calculate can you solve this

mysql only

id product rept payt
'1', 'Mouse', '1000.00', '0.00'
'2', 'Key', '2500.00', '1200.00'
'3', 'Lap', '8500.00', '300.00'
'4', 'CD', '900.00', '0.00'

INSERT INTO `test`.`tblp` (`id`, `product`, `rept`, `payt`) VALUES (1, 'Mouse', '1000', '0');

INSERT INTO `test`.`tblp` (`id`, `product`, `rept`, `payt`) VALUES (2, 'Key', '2500', '1200');

INSERT INTO `test`.`tblp` (`id`, `product`, `rept`, `payt`) VALUES (3, 'Lap', '8500', '300');

INSERT INTO `test`.`tblp` (`id`, `product`, `rept`, `payt`) VALUES (4, 'CD', '900', '0');

my ouput like this
id product rept payt bal
'1', 'Mouse', '1000.00', '0.00' 1000
'2', 'Key', '2500.00', '1200.00' 2300
'3', 'Lap', '8500.00', '300.00' 10500
'4', 'CD', '900.00', '0.00' 11400

 0 It is query for SQL Server...`SELECT a.id, a.product, a.rept, a.payt, (SELECT SUM(b.rept-b.payt ) FROM tblp b WHERE b.id <= a.id)FROM tblp aORDER BY a.id;` Mark This Response as Answer -- Chandu http://www.dotnetfunda.com/images/dnfmvp.gifJayakumars, if this helps please login to Mark As Answer. | Alert Moderator