Problem understanding SUM function with GROUP BY

  • I have code I'm trying to write to sum the time in decimal for each user_name:

    SELECT [user_name], dbo.fnGetDecimalTime([event_sec]) as 'Decimal_Time', 
    SUM(dbo.fnGetDecimalTime([event_sec])) as 'Decimal_Time_SUM'
    FROM [Charter].[dbo].[ConvoHrs]
    group by [user_name], [event_sec]
    order by [user_name], [event_sec] desc

    But my data comes back looking like this:

    user_name Decimal_Time Decimal_Time_SUM

    (b) Alexander Pierson     2.00 2.00

    (b) Alexander Pierson     1.63 1.63

    (b) Alexander Pierson     1.31 1.31

    (b) Alexander Pierson     0.57 0.57

    (b) Alexander Pierson     0.34 0.34

    (b) Alexander Pierson     0.21 0.21

    (b) Alexander Pierson     0.18 0.36

    (b) Alexander Pierson     0.13 0.13

     

    • This topic was modified 2 years, 4 months ago by  DaveBriCam.
  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • If you provide CREATE TABLE and some sample data, and tell us what is that you expect to see, perhaps more help could be provided. There are many reasons why queries misbehave, we need more info. This does not look like overly complicated - you are trying to summarize time spent by each user - but your query says something else. Tell us what you have and what you want to see.

     

     

     

    Zidar's Theorem: The best code is no code at all...

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

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