View previous topic :: View next topic
|
Author |
Message |
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I concur, the fields are understandable.
Anything else you'd like to know? |
|
Back to top |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
Please post the query which will fetch the records.
Thanks |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
dbz , thats a terrible query! |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
dbz , thats a terrible query! |
yes, even if it worked
but the TS irritated me.
and thx for your solution. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
yep...
quite too often some topics are just like sand-toilet-paper |
|
Back to top |
|
|
|