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 |
|
Anarking
Starting Member
13 Posts |
Posted - 2007-05-02 : 07:21:55
|
| Im trying to get the average Fuel Consumption for A Manufacturer that produces two or more cars, so far ive only been able to find all manufacturers Average Fuel consumption.Heres what I have so farSelect aManufacturer.MName, avg(FuelCons)From aCarJoin aBuilts On aBuilts.CName = aCar.CNameJoin aManufacturer On aBuilts.MName = aManufacturer.MNameGroup by aManufacturer.MNameThis produces nearly all I want only I need to be able to get only the Manufacturers who produce two or more Cars, ive tried implementing a few Count statements but nothings working, any ideas? |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-05-02 : 07:26:29
|
Somthing like this Select aManufacturer.MName, avg(FuelCons)From aCarJoin aBuilts On aBuilts.CName = aCar.CNameJoin aManufacturer On aBuilts.MName = aManufacturer.MName Having Count(1) >1 Group by aManufacturer.MName Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
Anarking
Starting Member
13 Posts |
Posted - 2007-05-02 : 07:28:29
|
| Hmm, thats giving me this error"Server: Msg 156, Level 15, State 1, Line 6Incorrect syntax near the keyword 'Group'." |
 |
|
|
Anarking
Starting Member
13 Posts |
Posted - 2007-05-02 : 07:30:16
|
| cool, got it when I changed it to this.Select aManufacturer.MName, avg(FuelCons) As 'Average Fuel Consumption'From aCarJoin aBuilts On aBuilts.CName = aCar.CNameJoin aManufacturer On aBuilts.MName = aManufacturer.MNameGroup by aManufacturer.MNameHaving count(aBuilts.CName) > 1 |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2007-05-02 : 07:35:13
|
| opps..its was a silly mistake.. good to know you figured it out.. !!Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|
|
|
|