x
login about faq Site discussion (meta-askssc)

How to make an average of data in sql server?

I have this data:

id time      act    ai   hr                    
1  3:26:00   null   5    4                    
2  3:26:00   null   5    4                    
3  3:27:00   7      null 4                    
4  3:27:00   6      5    4                    
6  3:27:00   null   5    4                    
7  3:28:00   null   5    4                    
8  3:28:00   null   5    4                    
9  4:26:00   null   5    4                    
10 4:36:00   null   5    4                    
11 5:26:00   6      5    4                    
12 5:36:00   null   5    4                    
13 5:46:00   null   5    null                    
14 6:26:00   null   5    4                    
15 7:26:00   null   null null                    

and I want the result like this:

id  time     act  ai  hr                    
1   3:26:00  5    9   8                    
2   3:26:00  null 5   4                    

and so on.

more ▼

asked Oct 31 '09 at 01:02 PM in Default

vikas intel gravatar image

vikas intel
11 1 2 2

It's very hard to read your text when you don't apply formatting. In general, just GROUP BY your ID field and take the AVG of your data field. Can you apply the code formatting to your post and also provide the table schema?

Oct 31 '09 at 03:53 PM Benjamin
(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.