Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

To fetch the counts as per the changes in the record

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
maxsubrat

New User


Joined: 27 Feb 2008
Posts: 78
Location: india

PostPosted: Thu Sep 22, 2011 12:34 pm    Post subject: To fetch the counts as per the changes in the record
Reply with quote

suppose i have a table with employ id and a field like history log

History log is a field where if any changes in the employ happens then the table will be updated

for ex:

Employ_Id History_log:

000012 joining
000012 promotion
000012 hike
000012 promotion
000012 dept change
000012 dept change
000012 dept change

000013 joining
000013 promotion
000013 Resign


so i want to fetch the counts of a employ as per the History log..

so my output would be like

Emp_Count Join Promotion Hike Dept_change Resign
02 02 03 01 03 01

i think all the fields are understandable in the output which is needed.

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

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7313

PostPosted: Thu Sep 22, 2011 1:43 pm    Post subject: Reply to: To fetch the counts as per the changes in the reco
Reply with quote

I concur, the fields are understandable.

Anything else you'd like to know?
Back to top
View user's profile Send private message
maxsubrat

New User


Joined: 27 Feb 2008
Posts: 78
Location: india

PostPosted: Thu Sep 22, 2011 2:17 pm    Post subject: Reply to: To fetch the counts as per the changes in the reco
Reply with quote

Please post the query which will fetch the records.

Thanks
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7313

PostPosted: Thu Sep 22, 2011 2:27 pm    Post subject: Reply to: To fetch the counts as per the changes in the reco
Reply with quote

Well, it's not really the way things work around here.

Do some research, find some examples, see what might apply to your requirement, try some things out. If you get stuck, show us what you have done and what problems remain.

You have colleagues, manuals and the web. Get going.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Sep 22, 2011 2:27 pm    Post subject:
Reply with quote

don't have z/OS DB2 available
so my syntax is not correct,
but??

Code:

with temp_tab(emp_id
values
select distinct(empl_id)
from emp_tab)
Select count(*) as num_emp
      ,0        as num_join
      ,0        as num_promo
      ,0        as num_hike
      ,0        as num_chg
      ,0        as num_resign
from temp_tab
union
Select 0        as num_emp
      ,count(*) as num_join
      ,0        as num_promo
      ,0        as num_hike
      ,0        as num_chg
      ,0        as num_resign
from emp_tab
where history_log = 'joining'
union
Select 0        as num_emp
      ,0        as num_join
      ,count(*) as num_promo
      ,0        as num_hike
      ,0        as num_chg
      ,0        as num_resign
from emp_tab
where history_log = 'promotion'
union
...  for hike
union
...  for chg
union
.... for resign
group by num_emp
        ,num_join
        ,num_promo
        ,num_hike
        ,num_chg
        ,num_resign
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Sep 22, 2011 2:43 pm    Post subject:
Reply with quote

If you bluntly have to ask for the query you should remove DB2 from your skillset.

otherwise you might want to check :

count(distint <colname>)
sum(case when <colname> = <value> then 1 else 0 end)
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Sep 22, 2011 2:44 pm    Post subject:
Reply with quote

dbz , thats a terrible query!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Sep 22, 2011 2:48 pm    Post subject:
Reply with quote

Quote:
dbz , thats a terrible query!

yes, even if it worked
but the TS irritated me.

and thx for your solution.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10241
Location: italy

PostPosted: Thu Sep 22, 2011 2:51 pm    Post subject: Reply to: To fetch the counts as per the changes in the reco
Reply with quote

yep...
quite too often some topics are just like sand-toilet-paper icon_biggrin.gif
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 Sort Large record length cmsmoon DFSORT/ICETOOL 14 Tue Apr 11, 2017 5:49 pm
No new posts Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm
No new posts Record Not found in AlX but record re... mukun264 COBOL Programming 7 Fri Mar 24, 2017 9:28 am
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us