Home / SIDU


    SQL row sum

    2018-11-02 00:00
    12864   0   0
    Test

    Given an SQL table
    
    ID Amt
    -- ---
    1 100
    2 200
    3 300
    
    Please write a MySQL statement to produce the following result:
    
    ID Amt Total
    -- --- -----
    1  100 100
    2  200 300
    3  300 600
    
    And here is an example SQL:
    
    SELECT a.ID, a.Amt, sum(b.Amt) AS Total
    FROM tab AS a
    JOIN tab AS b ON a.ID >= b.ID
    GROUP BY 1,2
    

    Back « SIDU feature request and bug
    Next » Wiki: Topnew DB helper

    Comments

    Leave a commentEdit comment

    Category