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 |
|
sital
Yak Posting Veteran
89 Posts |
Posted - 2008-12-10 : 08:00:13
|
| Hi all,use AdventureWorksselect Title,Average = avg(VacationHours) from HumanResources.Employee where Title in('Accountant','Account Payable','Specialist','Production Tech_W120','Buyer','Design Engineer','Accounts Manager')Group by all TitleThe Above query when executed displays the rows which has the title as 'Chief Executive Officer,Chief Financial Officer' etc. But I did not mention any thing related to 'Chief' Then Why it is displaying all such rows as the output? Is my Query Wrong? |
|
|
maevr
Posting Yak Master
169 Posts |
Posted - 2008-12-10 : 08:06:54
|
| Try remove all in the group by clause. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-12-10 : 08:30:19
|
| try thisselect Title,Average = avg(VacationHours) from HumanResources.Employee Group by Titlehaving Title in('Accountant','Account Payable','Specialist','Production Tech_W120','Buyer','Design Engineer','Accounts Manager') |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-12-10 : 08:39:24
|
Whenever possible, try to rewrite HAVING conditions as WHERE conditions in order to pre-filter the intermediate results before grouping.Remove that 'ALL' from the group by like maevr already wrote.Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|