Sum() Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • umeshpotdar
    New Member
    • Mar 2007
    • 34

    Sum() Function

    hello friends
    i hav a problem that i face today
    problem is

    i have a table in Mysql
    TableName---- wages

    ok

    records in that table are like

    wId Uid amount
    1 1 10000
    2 1 10000
    3 2 20000
    4 2 20000
    5 2 20000
    6 3 30000
    7 3 30000

    ok

    so i want sum of amount of distinct Uid

    i used foll. query
    Select * from wages group by Uid

    i got result for above

    wId Uid amount
    1 1 10000
    3 2 20000
    6 3 30000

    now i want sum of amount of these records
    means (10000+20000+30 000)

    so how can use one query do produce this result.

    Please help me.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Try This:

    [code=sql]

    SELECT wid,uid,SUM(amo unt) OVER() FROM
    (Select * from wages group by Uid)

    [/code]

    Comment

    • umeshpotdar
      New Member
      • Mar 2007
      • 34

      #3
      Originally posted by amitpatel66
      Try This:

      [code=sql]

      SELECT wid,uid,SUM(amo unt) OVER() FROM
      (Select * from wages group by Uid)

      [/code]

      Sorry Yar
      But it Did'nt worked at my side.
      plz
      tell me other trick to do same.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        This is basic SQL[code=sql]SELECT uid, SUM(amount) FROM wages GROUP BY uid[/code]Ronald

        Comment

        Working...