MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Total number of records

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
sanjayr321
Beginner


Joined: 25 Sep 2006
Posts: 28
Topics: 15

PostPosted: Tue Aug 28, 2007 12:05 am    Post subject: Total number of records Reply with quote

Hai All,

I need to find out the total number of records in a particular table, i.e I want to figure out the percentage of a group of employee..
for ex: consider EMPL table having total 10000 records and out of 10000 records 4000 are with EMPCODE = 'ACCT', if I know the numbers I will findout the percentage (4000/10000) x 100..

Is there any other way to find out the total number of records in a table other than selecting all the records, since it may have millions of records it will take long time to run...

Hope you understand my queries, pls give some suggestions, I looked at CARDF in SYSIBM tables, i can't find out from it..

Thanks..
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Aug 28, 2007 12:33 am    Post subject: Reply with quote

sanjayr321,

If you don't want to do a COUNT(*), then insure that the RUNSTATS are current, and look in the sysibm table for the count. The appendix of any SQL guide or reference will tell you in which sys table to look, as well as sample SQL for a query.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
sanjayr321
Beginner


Joined: 25 Sep 2006
Posts: 28
Topics: 15

PostPosted: Tue Aug 28, 2007 2:31 am    Post subject: Reply with quote

Hi,

sorry... i can't make sure that RUNSTATS are updating properly ( do not hav access for it) more ever CARDF in float format, how can I identify the number of records in the table from it.

Is there any other way....

Thanks..
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Aug 28, 2007 2:56 am    Post subject: Reply with quote

The sql manual will show you how to convert float to other datatypes.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Aug 28, 2007 7:30 am    Post subject: Reply with quote

sanjayr321,

Try this

Code:

SELECT (SUM(CASE WHEN EMPCODE = 'ACCT'
                THEN DECIMAL((1),13,4) 
                ELSE DECIMAL((0),13,4) 
            END) / COUNT(*)) * 100     
 FROM TABLE                         
 ;         


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Sarangadhar
Beginner


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Mon Sep 17, 2007 5:43 pm    Post subject: Reply with quote

Kolusu,
Its working..

What is the forlumal behind decimal ((1),13,4)?
_________________
Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Sep 18, 2007 7:21 am    Post subject: Reply with quote

Sarangadhar,


Code:

decimal ((1),13,4)?  = a value of 1 which should reprensted as 13 (9 whole numbers + 4 decimals)

ie.
Code:

000000001.0000


The reason for using decimals is OP wanted a percentage. Count(*) returns a integer number without any decimals.

for ex you have a table of 40 rows and out of 5 rows has a string 'mvsforums'

Now if you want find the percentage of rows with 'mvsforums' then

% = (5/40) * 100 = 12.5%

In Db2 5/40 yields 0 since there integer divided by integer results in a integer and you don't have any decimals.

But if you use 5.0000/40 it will yield .12500000000000 which is what OP needs

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group