Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query for selecting single type

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
sharad_shanu

New User


Joined: 03 Oct 2006
Posts: 40

PostPosted: Tue Aug 26, 2014 10:09 am    Post subject: Query for selecting single type
Reply with quote

Hi all,

I am struggling with a query with selection.

I have a distributor no with me (say 0001). Now this distributor can have multiple dealer like X001, X002 and so on. Each of these dealers can have one of the status like Open (O), closed (C), pending (P), Hold (H).

So one distributor can have any number of dealer whereas each dealer can have one of the status. So it looks like:

dist dealer status
0001 X001 C
0001 X002 H
0001 X003 P
0001 X004 H
0001 X005 O
0001 X006 O
0001 X007 P
0002 X001 O
0002 X002 O
0003 X001 C
0003 X002 H

Now I have the dist no and I wish to ascertain if there are only open dealer associated with it. I mean if there are any closed or held or pending dealers we should not select it.
A distributor can have several dealers but none of them should have status other than O.

In above data only distributor 0002 satisfies the condition.
I am struggling to figure out the query. Therefore calling for a help.

I am avoiding "NOT IN ('P', 'C', 'H')". Basically I want to use only 'O' in the query. Lets assume that there could be other codes/spaces as well. What I need to know that a distributor should have open dealers.

Thanks in advance.
Back to top
View user's profile Send private message

himanshu_pant

New User


Joined: 08 Jul 2014
Posts: 14
Location: India

PostPosted: Wed Aug 27, 2014 2:06 am    Post subject: Reply to: Query for selecting single type
Reply with quote

Hi,

You could try the below query.

Code:
select distinct a.dist
 from tab1 a
 where 'o' =  all
      (select b.status
          from tab1 b
        where b.dist = a.dist)


Let me know if it helps.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1736
Location: NY,USA

PostPosted: Wed Aug 27, 2014 9:26 pm    Post subject:
Reply with quote

Not Tested, please try..

Code:
Select a.dist,a.dealer
from table a,
where
a.dist NOT IN  (b.dist
                   from table b
                   Where b.status <> 'O'
                   group by b.dist)
ANd a.status = 'O'
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 16 Thu Jul 13, 2017 2:11 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
This topic is locked: you cannot edit posts or make replies. SDSF multiple spool datasets extracte... PJAlarcon CLIST & REXX 1 Fri Apr 21, 2017 10:50 pm
No new posts SORT JSON type of data maxsubrat DFSORT/ICETOOL 8 Wed Apr 19, 2017 6:01 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us