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
 

 

Can somebody help with this query?

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

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Thu Sep 02, 2010 7:15 pm    Post subject: Can somebody help with this query?
Reply with quote

I have a table which consists of the following fields

automaat-id
automaat-type
automaat-status
contract-id

If for 1 contract-id more than 1 (so 2 or more) different automaat-id occurs with apparaat-status 'A' and automaat-type = 'Pin' or 'Comb' count this as 1 (let's call this X)
I need to have the total of X

What's the best way?
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Sep 02, 2010 8:01 pm    Post subject:
Reply with quote

DB2 tables do not have fields, they have columns.

Also, column names use underscores, not hyphens.

what have you tried. If you say nothing, that is probably the number of responses that you will receive.
Back to top
View user's profile Send private message
revdpoel

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Thu Sep 02, 2010 10:00 pm    Post subject:
Reply with quote

I don't think this is a rather helpful and kind answer

I haven't tried anything since I don't know where to start
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu Sep 02, 2010 11:41 pm    Post subject:
Reply with quote

Hello,

Quote:
I haven't tried anything since I don't know where to start
Then you need to invest some time (and maybe some $) on SQL training/education/book(s).

This kind of material is part of most basic SQL classes/texts.

We can help when there are problems, but we are not able to "teach" from scratch.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 578
Location: USA

PostPosted: Fri Sep 03, 2010 1:01 am    Post subject:
Reply with quote

revdpoel,

Try this untested....

Code:
SELECT SUM(CNT) FROM                                           
        (SELECT COUNT(DISTINCT(CONTRACT-ID)) AS CNT
         FROM TABLE                                         
         WHERE APPARAAT-STATUS = 'A'                           
         AND   AUTOMAAT-TYPE IN ('PIN','COMB')                 
         GROUP BY CONTRACT-ID HAVING COUNT(AUTOMAAT-ID) > 1) A


Thanks,
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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


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