Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
how to count no of rows from all the tables ?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: how to count no of rows from all the tables ?
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

Moderator


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

PostPosted: Thu May 31, 2012 9:08 am    Post subject:
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    Post subject:
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    Post subject:
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

Senior Member


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

PostPosted: Thu May 31, 2012 1:52 pm    Post subject:
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    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 Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts SORT Trailer Count - LRECL Output co... amorante DFSORT/ICETOOL 5 Tue Aug 29, 2017 8:57 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us