Total Multiple Rows for a Unique Item

  • How do I obtain a sum of a field, when I have multiple records for the same item? Specifically, the Exceptions table has multiple rows that contain the same InspectionID, how do I sum up the total of all DmgTotal for a unique InspectionID? (SQL Server 2005) (I am a beginner at SQL).

    Exceptions table contains the following fields:

    InspectionID, DmgTotal

    Data Sample:

    Row#InspectionIDDmgTotal

    #19000120.00

    #2900059.00

    #3900042.00

    #49001400.00

    #59002500.00

    #69002250.00

    #7900330.00

    #8900340.00

    The result I would like to get is:

    InspectioniDTOTAL

    9000179.00

    9001400.00

    9002750.00

    900370.00

  • Look up SUM and GROUP BY in the SQL Books Online (SQL Help file, press F1 in management studio to open)

    If you can't get it right, post what you have and I'll help you fix it.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks, I got it.:-P

  • Excellent. 🙂

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply