IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

count from 2 tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 61
Location: San Diego

PostPosted: Thu Nov 25, 2010 7:30 pm
Reply with quote

Hi ,
I have 2 tables from which i need to get the counts of debits,credits for a list of account numbers. These 2 tables are related by a column called deposit number.
table a
Code:

type            accountno               deposit no.
cr                000110                1234
db                000321                1234
db                31200                 1234
cr                000220                5678
db                789000                5678
cr                23452                 4324
db                48623                 4324


table b
Code:

type            accountno               deposit no.
db1               5435345                1234
db1               89076                  1234
db1               789789                 1234
db1               9875576                5678
db1               534534534              5678

when my inputs to the query is 000110 ,000220 the output should be

Code:

account no   type count
000110        cr   1
000110        db   5
000220        cr   1
000220        db   3

P.s the debits have a value of db in table a and value of db1 in table b

tried my best, so far no luck icon_sad.gif

Thanks in advance for any tips or hints

Rakesh
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Nov 25, 2010 7:55 pm
Reply with quote

this works for cr=> db, I don't know what you want as output when you enter a db account like 789789 as input.
Code:
select type,accountno,count(*)
from
(select accountno,'cr' as type
  from tabA where type = 'cr'
union all
select A.accountno,'db' as type
  from tabA a1 , taba a2
 where a2.depositno = a1.depositno
    and a1.type = 'cr' and a2.type = 'db'
union all
select A.accountno,'db' as type
 from tabA a1 , tabb b2
 where b2.depositno = a1.depositno
    and a1.type = 'cr' and b2.type = 'db1'

) X
group by type,accountno
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts count contained values of several col... DB2 5
No new posts DB2 Query to get the count of Unique ... DB2 2
No new posts Question regarding ISPF tables with T... TSO/ISPF 11
No new posts To join 2 tables and to join 3rd tabl... DB2 8
No new posts CA7 count with DATE variable CA Products 0
Search our Forums:


Back to Top