I am creating one SQL query for stock entry. In the last column, I need the total of the previous stock purchase.
S No    Product Code    Qty     Qty Total
1       PO1             5       5  
2       PO1             12      17
3       PO1             10      27
4       PO1              8      35
5       PO1              9      44
6       PO1             16      60
In every row of the last column, I am adding all the previous quantity for example S no. 1 quantity is 5. In S No. 2 I am adding quantity 5 and 12=17. S No 3 I am adding 5 + 12+10=27 and Soo on.
I am sorry if it is a duplicate question. I search google and StackOverflow but didn't get the answer. I am new to MySQL I have added query below. I am new to SQL, any help appreciated,
Thanks in Advance.
CREATE TABLE `stock_table` (
  `ID` int(11) NOT NULL,
  `product_code` varchar(20) NOT NULL,
  `qty` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `stock_table` (`ID`, `product_code`, `qty`) VALUES
(1, 'PO1', 5),
(2, 'PO1', 12),
(3, 'PO1', 10),
(4, 'PO1', 8),
(5, 'PO1', 9),
(6, 'PO1', 16);