0

我对 SQL 很陌生,我需要这样的输出。我有一张桌子

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

和输出应该是

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

请告诉我此输出的查询。

4

1 回答 1

1

你需要这个:

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

演示 SQLFiddle

于 2013-01-07T05:24:40.520 回答