Stack User
Stack User

Reputation: 1398

Get the sum of column

I want to sum the below column. How can I do it?

When I use

sum(DATEDIFF ( HOUR , startDate, endDate) / 10.0 )

it gives this output:

(No column name)
1.000000
0.300000
1.000000
1.000000
1.000000
1.000000
0.300000

how can I sum this column?

the whole query:

SELECT  SUM(DATEDIFF ( HOUR , StartTime , EndTime ) / 10.0 ) FROM [y]
     INNER JOIN [x] ON [x].UserID = [y].ID  
WHERE StartTime BETWEEN '20120709' AND '20120714' AND UserID = 1
    GROUP BY StartTime, [y].ID, [y].Name, EndTime 
    ORDER BY StartTime

Upvotes: 0

Views: 102

Answers (2)

ErikE
ErikE

Reputation: 50271

You have a GROUP BY clause and shouldn't. Remove it and try again.

If that's not right and you do need it, then we need more information, please! What result are you trying to get?

If you GROUP BY a column, then for each different value in that column you will get a separate row.

Stop looking at the query and give an example result you'd like to see. Or tell us the question you want to answer.

Upvotes: 1

walrii
walrii

Reputation: 3522

Remove your GROUP BY clause. It is causing the multiple rows. If you only want one sum, then ORDER BY is also unneeded.

Upvotes: 1

Related Questions