Many times, you required to show information of each transaction and also keep a Running Total and Final Total like GridView in Asp.Net. Now I am going to explain, how can you achieve this using SQL Query in simple and easy way.
Suppose you have the below order table and has the data as shown below:
select CO.CustomerID, CO.CustomerName
,(select sum(Amount) from [order]
where OrderID <=ord.OrderID)
from Customer CO inner join [order] as ord on CO.CustomerID=ord.CustomerID