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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Returning Averages from tables

Author  Topic 

kporg
Starting Member

5 Posts

Posted - 2008-01-29 : 15:50:01
I have a table that looks like this

UniqueID Score
1 67
1 78
2 33
3 77
1 89
2 100

I want a resultset that looks like this
UniqueID Average
1 78
2 66.5
3 77

How do I get it???
Please help............and Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-01-29 : 15:51:45
SELECT UniqueID, AVG(Score) AS Average
FROM YourTable
GROUP BY UniqueID

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

kporg
Starting Member

5 Posts

Posted - 2008-01-29 : 16:14:44

Very Cool - now lets say I wanted to write those results into a table like this

UniqueID Average

Thanks again
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-29 : 16:17:36
Do you want to continue Tara?
This is way to difficult for me...



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-01-30 : 15:49:44


kporg, use SELECT INTO to put the results into a table. Check BOL for details on the syntax.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

kporg
Starting Member

5 Posts

Posted - 2008-01-31 : 11:37:54
Got it! Thanks!
Go to Top of Page
   

- Advertisement -