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

Result should contain one open id which has minimum eff_dt


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

New User


Joined: 10 Apr 2006
Posts: 14

PostPosted: Fri Oct 03, 2008 8:40 pm
Reply with quote

i have following database
Code:

id    status     eff-dt        exp-dt
---------------------------------------------------
001    open     2008-05-01         _
002    open     2008-04-01         _
003    open     2008-03-01         _
004    closed   2008-03-01     2008-05-01
005    closed   2008-04-01     2008-07-01


my desired result should contain one open id which has minimum eff_dt and one closed id which has maximum expiry date.

like
Code:

id    status     eff-dt        exp-dt
---------------------------------------------------
003    open     2008-03-01         _
005    closed   2008-04-01     2008-07-01
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 03, 2008 11:39 pm
Reply with quote

you've set-up unrealistic data. Require that solutions use this as column value definitions:
Code:

id    status     eff-dt        exp-dt
---------------------------------------------------
001    open     2008-05-01         _
002    open     2008-04-01         _
003    OPEN     2008-03-01         _
004    open     2008-04-01         _
005    Open     2008-03-01         _
006    closed   2008-03-01     2008-05-01
007    CLOSED   2008-04-01     2008-07-01
008    closed   2008-03-01     2008-05-01
009    Closed   2008-02-01     2008-07-01


unfortunately, in the real world, multiple rows with the same value (which ends up being a min or max) exist.
also
keep in mind, using lower case data a column values means you either must stipulate only one or the other, or look for both. Believe me, even though your INSERTs may be coded as upper or lower, some idiot with DB2 File-Aid or Spufi, or QMF can make life really difficult.

The solution taking into account these values is something you want someone to provide. A query for your data would not work for mine, unless coded for multiple MINs, MAXs, and case values.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 03, 2008 11:40 pm
Reply with quote

Plus, are the date fields of DATE Datatype, integer, or char?
Back to top
View user's profile Send private message
paritosh mathur

New User


Joined: 10 Apr 2006
Posts: 14

PostPosted: Tue Oct 07, 2008 9:26 am
Reply with quote

hey dick i have shown that data as an example only. and date is in date format. even open and close cases are also defined while inserting data.
Anyway i have got the solution which is (as per my data)-

Code:

select * from table where
eff_dt in (
(select min(eff_dt) from table where status = 'open'),
(select eff_dt from table where exp_dt in (select max(exp_dt) from table where status = 'closed'))
);


thanx for ur suggestions.
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 Calling an Open C library function in... CICS 1
No new posts first column truncated in search result IBM Tools 13
No new posts Open VSAM File in IMS DC Region - DFS... IMS DB/DC 0
No new posts SDSF like solution in EJES (store com... All Other Mainframe Topics 4
No new posts executing XCTL command in COBOL witho... CICS 10
Search our Forums:

Back to Top