| 
	
 | 
 Posted by Bosconian on 03/02/06 05:45 
"dottty" <dottty@noemailpls.met> wrote in message 
news:4406695a$0$15795$14726298@news.sunsite.dk... 
> Hi, 
> i have a table that has the following fields: 
> id, name, dept, pay 
> 1, John, Sales, 4000 
> 2, Peter, HR,  5000 
> etc. 
> 
> How do i count how many people there are in each dept with an sql query? 
> 
> I find this surprisingly difficult, given the fact that i can sum the 
total 
> pay for each dept by using: 
> $query=" 
> Select sum(if (dept='HR', pay, 0)) as hrpay, ...... 
> "; 
> 
> TIA 
> 
> 
> 
 
SELECT Count(dept) AS deptcount 
FROM [table] 
GROUP BY id
 
  
Navigation:
[Reply to this message] 
 |