Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Average

Author  Topic 

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-31 : 00:27:56
My table has two columns:

Name Scores
Michael 20
Roel 21
Ryan 22
Ryan 15
Michael 16

I would like to get the average scores for each name. What should be the statement?

Thanks

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-07-31 : 00:30:59
Seriously. Look up aggregate functions in Books Online.

e4 d5 xd5 Nf6
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-31 : 00:32:11
How's it?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-31 : 00:51:49
This is from the Books OnLine
http://msdn.microsoft.com/en-us/library/ms177677.aspx?n=0


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pootle_flump

1064 Posts

Posted - 2008-07-31 : 04:26:58
quote:
Originally posted by blindman

Seriously. Look up aggregate functions in Books Online.

I'm inferring that you expect the rest of your answers to be taken lightly then.
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-31 : 05:45:27
HI,
chk this.


select name,avg(scores)as avg_scores from table_name group by name
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-31 : 09:26:50
quote:
Originally posted by VGuyz

HI,
chk this.


select name,avg(scores)as avg_scores from table_name group by name


you might need to modify it like this if you want exact average and Score is of type integer
select name,avg(scores*1.0)as avg_scores from table_name group by name
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-31 : 09:39:10

quote:

you might need to modify it like this if you want exact average and Score is of type integer

select name,avg(scores*1.0)as avg_scores from table_name group by name



ya,
I missed it,
thanks a lot.
Go to Top of Page
   

- Advertisement -