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: 1624
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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