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.
| Author |
Topic |
|
ijjed
Starting Member
1 Post |
Posted - 2012-01-30 : 11:48:03
|
| Hi,Firstly, these are my tables:CLASSclass_id class_name1 Donkeys2 Monkeys4 Classic9 HumansCOURSESclass_id courses_number9 69 21 32 2I would like to print average course_number for each class_name.So for class_name Donkeys would have average course_number 3.And for clasS_name Humans, average course_number is 4.If the class_name does not have any average number, it would still be listed. In this example, class_name Classic, would not be listed.Do you get my point? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-30 : 12:38:49
|
| [code]SELECT c.Class_name,COALESCE(cr.AvgCrs,0) AS AvgCrsFROM CLASS cLEFT JOIN (SELECT Class_id,AVG(courses_number*1.0) AS AvgCrs FROM COURSES GROUP BY Class_Id)crON cr.Class_Id = c.Class_id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|