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

how to count no of rows from all the tables ?


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

New User


Joined: 17 Mar 2008
Posts: 27
Location: banaglore

PostPosted: Thu May 31, 2012 7:42 am
Reply with quote

Hi ,

I am trying to count no of rows from two tables as:

SELECT SUM(C.CNTR) FROM (
SELECT ID,COUNT(*) AS CNTR
FROM TABLEA ,
TABLEB
WHERE AN_ID = BN_ID
AND AN_MTH = 01
GROUP BY AN_ID
HAVING SUM(AN_AMNT) > 100 ) C;

i am getting errors as (*) is not valid . Please suggest.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu May 31, 2012 9:08 am
Reply with quote

I understand you wanted to count number of records which is present in table for the below where condition & having

Code:

 SELECT COUNT(*) AS CNTR FROM TABLEA , TABLEB WHERE AN_ID = BN_ID AND AN_MTH = 01 GROUP BY AN_ID HAVING SUM(AN_AMNT) > 100


Why dont you try the above
Back to top
View user's profile Send private message
vyasricha

New User


Joined: 17 Mar 2008
Posts: 27
Location: banaglore

PostPosted: Thu May 31, 2012 9:29 am
Reply with quote

Thanks for your reply, this will give me only count per group but i want to sum of count - for all rows.
Back to top
View user's profile Send private message
vyasricha

New User


Joined: 17 Mar 2008
Posts: 27
Location: banaglore

PostPosted: Thu May 31, 2012 10:02 am
Reply with quote

HI All,

The below query is working fine :
:
SELECT SUM(C.CNTR) FROM (
SELECT A.ID,COUNT(*) AS CNTR
FROM TABLEA ,
TABLEB
WHERE AN_ID = BN_ID
AND AN_MTH = 01
GROUP BY AN_ID
HAVING SUM(AN_AMNT) > 100 ) C;

Thanks for your help !
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu May 31, 2012 1:52 pm
Reply with quote

So using "A.ID" instead of "ID" for Table-A solved the problem?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
Search our Forums:

Back to Top