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

To fetch the counts as per the changes in the record


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

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Thu Sep 22, 2011 12:34 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 1:43 pm
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

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Thu Sep 22, 2011 2:17 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 2:27 pm
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
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
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
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Sep 22, 2011 2:51 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 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
Search our Forums:

Back to Top