0

I am very new in SQL and i need a output like this. I have a table

Name    Price 
----------------
A        10    
B        20   
C        30

and output should be

Name    Price    running  
--------------------------
A       10          10    
B       20          30  
C       30          60

Please Tell me the Query for this output.

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
Ankur Gupta
  • 933
  • 3
  • 15
  • 27

1 Answers1

1

You need this:

select t1.Name, t1.Price,
    SUM(t2.Price) as running
    from your_table t1 inner join your_table t2
on t1.Name >= t2.Name
group by t1.Name, t1.Price
order by t1.Name

Demo SQLFiddle

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105