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

SQL to know the maximum leave taker in the year of 2005


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

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Fri Mar 23, 2007 9:53 pm
Reply with quote

i accept ur word dick
but i need only who is taking maximum leave takers

by
raj
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Mar 23, 2007 10:00 pm
Reply with quote

Hello, raj,

Thank you for:
Quote:
i accept ur word dick


I am not clear on what this tells me:
Quote:
but i need only who is taking maximum leave takers


To continue with your example, what would you want for the result if there were several people who had taken 16 days. Let's say that in addition to the sample you posted, there was also:
12380 16
12478 16
12500 16
Should all of them be reported - i would think so if you want to know the empno(s) who took max leave?
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Fri Mar 23, 2007 10:02 pm
Reply with quote

yes correct dick
i want that only what u said in the examples


by
raj
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Mar 23, 2007 10:17 pm
Reply with quote

Hello raj,

That brings me back to
Quote:
I do not believe this solution will be found in a simple, efficient SQL query.


If this was my requirement, i would set up a cursor that would allow me to fetch all of the rows in the "leave" table keeping the empno and the "leave days" calculation.

As i fetched the entries, i would RELEASE them to an internal sort that is sorted on ascending empno. I would then RETURN the entries from the sort and sum by empno.

Each time i encountered a new empno, i would check the current sum against a working data field with the previous "max". If the number is less, clear the "sum" and continue.

If the sum is equal to the "max" move the empno into the "next" position of an array (defined to hold as many empnos as are likely to "tie" for max leave).

If the sum is greater than the stored max, move spaces to the array and set the displacement back to the beginning, move the empno to the first array entry and save the "new" max value.

When the process completes (the RETURN raises the AT END condition), the stored max is the number you want and the entries in the array are all of the empnos who have taken the "max" leave.

Please let me know if any of that is not clear.
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Fri Mar 23, 2007 10:22 pm
Reply with quote

yes u said correct way but its too big na
i need in one query

by
raj
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Mar 23, 2007 10:24 pm
Reply with quote

Good Luck icon_smile.gif
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Mar 27, 2007 5:35 pm
Reply with quote

i have another one query
for example

in one table

empname empid date of birth


i want to take person who is the age between 25 to 30

this is my queary
any body know pls tell me the query

thanks and regards
raj
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Tue Mar 27, 2007 8:19 pm
Reply with quote

SELECT * FROM SOMETABLE
WHERE YEAR(CURRENT TIMESTAMP) - YEAR(DOB) BETWEEN 25 & 30

I have not tested this query. Let me know if this doesnt work.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 27, 2007 8:56 pm
Reply with quote

Hello,

That may get close, but will give some results that should not be "hits". For example, most of the people born in 1982 are not yet 25, but i believe this query will "find" them as being 25. . . .
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Wed Mar 28, 2007 12:40 pm
Reply with quote

Yeah, You are right.
Month and Day should also be considered to get the exact results.
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 Goto page Previous  1, 2

 


Similar Topics
Topic Forum Replies
No new posts How to extract the data for current y... DFSORT/ICETOOL 8
No new posts SORT ERROR PARAMETER VALUE EXCEEDS M... DFSORT/ICETOOL 12
No new posts Increase the Maximum Length of LRECL ... JCL & VSAM 5
No new posts Vision plus req. In Pune 5 to 10 year Mainframe Jobs 0
No new posts Logic to skip Maximum time-stamp and ... DB2 2
Search our Forums:

Back to Top