How can I use two or more COUNT()s in one SELECT statament?

Posted by jjj on Stack Overflow See other posts from Stack Overflow or by jjj
Published on 2010-03-17T05:42:22Z Indexed on 2010/03/17 6:11 UTC
Read the original article Hit count: 146

Filed under:
|
|

i develop this code:

SELECT COUNT(NewEmployee.EmployeeID), NewEmployee.EmployeeId,EmployeeName 
FROM NewEmployee INNER JOIN NewTimeAttendance  
  ON NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID 
  and NewTimeAttendance.TotalTime is  null 
  and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null)
  and (month = 1 or month = 2 or month = 3)  
GROUP BY NewEmployee.EmployeeID, EmployeeName
order by EmployeeID

from my previous two questions selecting null stuff and counting issue...that amazing code is working beautifully fine..but now i need to select more than one count...

...searched (google) .... found alias...tried:

SELECT COUNT(NewEmployee.EmployeeID) as attenddays, COUNT(NewEmployee.EmployeeID) as empabsent
 , NewEmployee.EmployeeId,EmployeeName 
 FROM NewEmployee INNER JOIN NewTimeAttendance  
  ON empabsent =NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID 
  and NewTimeAttendance.TotalTime is  null 
  and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
    and (month=1 or month =2 or month = 3) , 
    attenddays = NewTimeAttendance.EmployeeID 
  and NewTimeAttendance.TotalTime is  null 
  and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
    and (month=1 or month =2 or month = 3)
GROUP BY NewEmployee.EmployeeID, EmployeeName  order by EmployeeID

Incorrect syntax near '='.

second try:

SELECT COUNT(NewEmployee.EmployeeID) as attenddays, COUNT(NewEmployee.EmployeeID) as absentdays,
NewEmployee.EmployeeId,EmployeeName 
 FROM NewEmployee INNER JOIN NewTimeAttendance  
  ON attenddays(NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID 
  and NewTimeAttendance.TotalTime is  null 
  and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
    and (month=1 or month =2 or month = 3)) ,
    absentdays(NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID 
  and NewTimeAttendance.TotalTime is  null 
  and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
    and (month=1 or month =2 or month = 3))
GROUP BY NewEmployee.EmployeeID, EmployeeName  order by EmployeeID

Incorrect syntax near '='.

not very good ideas... so ...help

thanks in advance

© Stack Overflow or respective owner

Related posts about sql

Related posts about join