View previous topic :: View next topic
|
Author |
Message |
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
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 |
|
|
|