How to solve this Sum Query Mentor - Bandi

Posted by Jayakumars under ASP.NET AJAX on 5/4/2015 | Points: 10 | Views : 418 | 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

Mark as Answer if its helpful to you


Responses

Posted by: Bandi on: 5/5/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer
http://stackoverflow.com/questions/9394418/calculate-balance-with-mysql

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 5/5/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
bandi

I need same operation for sql server? how will do


Mark as Answer if its helpful to you

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 5/5/2015 [Member] [MVP] Platinum | Points: 25

Up
0
Down
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 a
ORDER BY a.id;


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response