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: 10277
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: 1281
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: 1281
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 Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm


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