IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Find the entries where the employee has more than one DOS


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sudhakarraju

New User


Joined: 05 May 2005
Posts: 31

PostPosted: Tue Mar 02, 2010 10:09 pm
Reply with quote

I have the below sample table

Code:

¦---¦-----------¦----¦
¦EMP¦ DOS       ¦AMT ¦
¦---¦-----------¦----¦
¦10 ¦2009-01-01 ¦10  ¦
¦10 ¦2010-03-01 ¦21  ¦
¦11 ¦2010-01-01 ¦25  ¦
¦11 ¦2010-02-01 ¦23  ¦
¦12 ¦2010-02-28 ¦25  ¦
¦13 ¦2010-02-28 ¦10  ¦
¦13 ¦2010-03-01 ¦12  ¦
¦14 ¦2009-01-01 ¦11  ¦
¦14 ¦2009-02-01 ¦10  ¦
----------------------


I need all the entries where the employee has more than one DOS
and atleast one of the DOS should be in the past one week.

in the above table EMP - 10 & 13 entries should only be in the result.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Mar 02, 2010 11:05 pm
Reply with quote

past one week = last seven days ?

1) all entries = all emp no :

Code:
select emp from tab1 A
where exists
(select * from tab1 b
 where a.emp = b.emp and b.dos <> a.dos)
and a.dos > current_date - 7 days
group by emp


2) all entries = all rows:

Code:
select * from tab1 A
where exists
(select * from tab1 b
 where a.emp = b.emp and b.dos <> a.dos)
and exists
(select * from tab1 c
 where a.emp = c.emp
    and c.dos > current_date - 7 days)
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed Mar 03, 2010 10:12 am
Reply with quote

This can also work.......

Code:
select week(dos), dos from  emptab
where week(dos) = week(current date) - 1;


Sushanth
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
No new posts Find the occurrence of Key Field (Par... DFSORT/ICETOOL 6
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts Need to find a specific STRING COBOL Programming 11
Search our Forums:

Back to Top