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
 Aggregate Function/ORDER BY

Author  Topic 

bobross80
Starting Member

11 Posts

Posted - 2008-03-21 : 18:04:11
SELECT [LastNameOfProfessor], avg(ProfessorRating) AS [Average] FROM [Table1] GROUP BY [LastNameOfProfessor]

How would I order this by [Average]?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-03-21 : 18:40:29
order by avg(professorrating)

when in doubt -- try it!

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-03-21 : 18:47:06
you can also order it by [Average]!

order by [Average]

Jim
Go to Top of Page

bobross80
Starting Member

11 Posts

Posted - 2008-03-21 : 19:29:07
quote:
Originally posted by jsmith8858

order by avg(professorrating)

when in doubt -- try it!

- Jeff
http://weblogs.sqlteam.com/JeffS




Thanks a lot it works, but I thought ordering by an aggregate function is illegal.
Go to Top of Page

bobross80
Starting Member

11 Posts

Posted - 2008-03-21 : 19:30:49
quote:
Originally posted by jimf

you can also order it by [Average]!

order by [Average]

Jim



The system I'm using will not let me order by an alias for some reason. Thanks though.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-03-21 : 19:36:01
Well you've posted on a Microsoft SQL Server forum, so our answers will be for that system. If you are using a different system, then you should specify that in your initial post.

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

bobross80
Starting Member

11 Posts

Posted - 2008-03-21 : 20:33:43
quote:
Originally posted by tkizer

Well you've posted on a Microsoft SQL Server forum, so our answers will be for that system. If you are using a different system, then you should specify that in your initial post.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/



I'm using this select command for an asp.net 2.0 webpage and inside a datasource for a grid view control. The webpage is hosted on a ms server and I'm not exactly sure how it's configured/updated.

Go to Top of Page
   

- Advertisement -