MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need Query to get the count based on year and orgin id

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
lacoe1
Beginner


Joined: 24 Feb 2005
Posts: 33
Topics: 17

PostPosted: Thu Oct 19, 2006 4:52 pm    Post subject: Need Query to get the count based on year and orgin id Reply with quote

Example:

Code:

ORGID             EMPLID     CHECKDT
=====             ======    ==========
10100             XXXXXX    10/13/2005
10100             XXXXXX    01/05/2006 
10100             YYYYYY    09/02/2005   
10100             YYYYYY    09/20/2005
10100             YYYYYY    10/05/2005
10100             YYYYYY    10/20/2006 
10100             YYYYYY    11/04/2006 
64000             ZZZZZZZ   09/02/2005 
64000             ZZZZZZZ   09/20/2005 
64000             ZZZZZZZ   10/05/2006
69000             MMMMMM    01/30/2006
89999             NNNNNNN   05/30/2005   



For number of employees per Org who got paid in 2005 I need to display my sql output like this. Not interested to count for other years
-------------------------------------------------------------------------------------------
Code:

ORG            EMPLCOUNT

10100           2           
64000           1
69000           0
89999           1

Any suggestions ?
Back to top
View user's profile Send private message
coolman
Intermediate


Joined: 03 Jan 2003
Posts: 283
Topics: 27
Location: US

PostPosted: Thu Oct 19, 2006 5:24 pm    Post subject: Reply with quote

Are you showing the right results? I don't think no - Here's an untested SQL for actually what you had requested

Code:

SELECT ORGID
      ,COUNT(*)
  FROM EMP
 GROUP BY ORG
HAVING YEAR(CHECKDT) = '2005'
;

________
Mega Cruiser


Last edited by coolman on Sat Feb 05, 2011 1:55 am; edited 1 time in total
Back to top
View user's profile Send private message
lacoe1
Beginner


Joined: 24 Feb 2005
Posts: 33
Topics: 17

PostPosted: Thu Oct 19, 2006 5:46 pm    Post subject: Reply with quote

coolman, your query will result in extra count, for example

10100 YYYYYY 09/02/2005
10100 YYYYYY 09/20/2005
10100 YYYYYY 10/05/2005
10100 YYYYYY 10/20/2006
10100 YYYYYY 11/04/2006

Even though YYYYY got paid 3 times in 2005 he should be counted as 1 employee.
Your query will result in 3. The correct count is 1.
Back to top
View user's profile Send private message
lacoe1
Beginner


Joined: 24 Feb 2005
Posts: 33
Topics: 17

PostPosted: Thu Oct 19, 2006 6:06 pm    Post subject: Reply with quote

I guess this will work me.A friend helped me
Code:

SELECT ORGID  AS DISTRICT                       
      ,COUNT(DISTINCT EMPLID) AS EMPL_COUNT       
  FROM TABLE                           
 WHERE CHECKDT BETWEEN '01/01/2005' AND '12/31/2005'
 GROUP BY ORGID                                     
 WITH  UR;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group