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

DB2 query


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

New User


Joined: 06 May 2008
Posts: 96
Location: Delhi

PostPosted: Wed Oct 07, 2009 11:49 am
Reply with quote

Quarter Year Project Prm1 Prm2 Prm3 prm4
==============================================
1 2008 ABC Y N Y N
2 2008 ABC Y Y N Y
3 2008 ABC N N N Y
4 2008 ABC Y Y Y Y
1 2008 XYZ N N N N
2 2008 XYZ Y N N Y
3 2008 XYZ Y Y N Y
4 2008 XYZ Y N Y Y
===============================================

I want output like
=============================================
Year Project Prm1 Count Prm2 Count Prm3 Count Prm4 Count
==============================================
2008 ABC 3 2 2 3


I wan to show how many times a certain project faired (passed) on each parameter in a year using a single SELECT statement.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Oct 07, 2009 12:18 pm
Reply with quote

see
ibmmainframes.com/viewtopic.php?t=44244&highlight=
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Wed Oct 07, 2009 3:19 pm
Reply with quote

Please find below query that could be used

I have only used two PRM you can use four in same way
select year
,project
,sum(prm1) as prm_Count1
,sum(prm2) as prm_Count2
from
(select year
,project
,Case when prm1 = 'Y' then
1
else
0
end as prm1
,Case when prm2 = 'Y' then
1
else
0
end as Prm2
from project1) proj group by
year,project;
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Wed Oct 07, 2009 4:02 pm
Reply with quote

Is this was a classroom work or asked during interview icon_exclaim.gif icon_question.gif
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Oct 07, 2009 8:01 pm
Reply with quote

The stuff people dare to put online icon_smile.gif

Code:
select year
,project
,sum(Case when prm1 = 'Y' then 1 else 0 end ) as prm_Count1
,sum(Case when prm2 = 'Y' then 1 else 0 end ) as prm_Count2
,sum(Case when prm3 = 'Y' then 1 else 0 end ) as prm_Count3
,sum(Case when prm4 = 'Y' then 1 else 0 end ) as prm_Count4

from project1
 group by year,project;
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Oct 07, 2009 8:05 pm
Reply with quote

are you in the same class as Abnikant ?

ibmmainframes.com/viewtopic.php?t=44244
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top