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
 IN operator

Author  Topic 

sital
Yak Posting Veteran

89 Posts

Posted - 2008-12-10 : 08:00:13
Hi all,

use AdventureWorks
select 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 Title

The 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.
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-10 : 08:30:19
try this

select
Title,
Average = avg(VacationHours)
from HumanResources.Employee
Group by Title
having Title in('Accountant','Account Payable','Specialist','Production Tech_W120','Buyer','Design Engineer','Accounts Manager')
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -