Count records and compare with a field of a table



IBM's flagship relational database management system

Count records and compare with a field of a table

Postby vegafacundodaniel » Tue Oct 19, 2010 4:54 pm

Hello,

I need help please :

I need to make a query to count records (grouping by a field, for example "country") and compare them against the value of a field of a table.

Any idea ?

Thanks in advance !
vegafacundodaniel
 
Posts: 61
Joined: Tue Jul 20, 2010 4:27 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Count records and compare with a field of a table

 

Re: Count records and compare with a field of a table

Postby Akatsukami » Tue Oct 19, 2010 6:52 pm

Your request is not sufficiently coherent to give any definite answer.

Where will the records come from: a PS data set ("flat file")? an ESDS? a KSDS? an IMS or DB2 data base? (in which case the term "records" is incorrect; it should be "segments" or "rows").
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Count records and compare with a field of a table

Postby GuyC » Tue Oct 19, 2010 6:54 pm

something like these : (all different performance depending on #rows and indexes)?
non-correlated :
select * from
(select ctry,count(*) as cnt from tab1 group by ctry)  A
, tab2 B
where A.ctry = B.ctry and A.cnt <> B.cnt

or
correlated
select * from
tab2 B
join table (select count(*) as cnt from tab1 A1 where A1.ctry = B.ctry )  A on 1=1
where A.cnt <> B.cnt

or
in where subselect (actual count(*) does not show up in result)
select * from
tab2 B
where B.cnt <> (select count(*) as cnt from tab1 A1 where A1.ctry = B.ctry ) 
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post