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
 

 

DB2 query

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

New User


Joined: 06 May 2008
Posts: 90
Location: Chennai

PostPosted: Wed Oct 07, 2009 11:49 am    Post subject: DB2 query
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Wed Oct 07, 2009 12:18 pm    Post subject: Reply to: DB2 query
Reply with quote

see
http://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    Post subject: Reply to: DB2 query
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    Post subject:
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: 1278
Location: Belgium

PostPosted: Wed Oct 07, 2009 8:01 pm    Post subject:
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: 1278
Location: Belgium

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

are you in the same class as Abnikant ?

http://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    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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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