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

Using Sql queries, is a output like this possible


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

New User


Joined: 04 Sep 2006
Posts: 11

PostPosted: Thu Mar 22, 2007 5:22 pm
Reply with quote

I have a table like -
TYPE COLOUR
---- --------
R1 YELLOW
R1 YELLOW
R1 RED
R1 BLUE
R1 GREY
R2 WHITE
R2 YELLOW
R2 GREEN
R2 GREY

Using Sql queries, is a output like this possible?

Code:
    YELLOW RED BLUE GREY WHITE GREEN
R1    2     1    1   1     0     0
R2    1     0    0   1     1     1
Back to top
View user's profile Send private message
mkk157

Active User


Joined: 17 May 2006
Posts: 310

PostPosted: Thu Mar 22, 2007 8:03 pm
Reply with quote

Hi baidyanath_biswas,

Here u r trying to make the fields into columns. I believe it is not possible.
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Thu Mar 22, 2007 9:37 pm
Reply with quote

Think you have to do RND on this.
Back to top
View user's profile Send private message
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Thu Mar 22, 2007 11:03 pm
Reply with quote

We used do these using QMF query and a QMF form. I think u can do this using the USAGE in a QMF form.
Back to top
View user's profile Send private message
baidyanath_biswas

New User


Joined: 04 Sep 2006
Posts: 11

PostPosted: Fri Mar 23, 2007 2:20 pm
Reply with quote

Any help guys?? Actually even if i want to search in the net for this particular thing,what to give as keyword to search? i donno icon_sad.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Mar 23, 2007 8:03 pm
Reply with quote

Hello,

If you want this quickly, it is a simple matter to write a program that retrieves the rows and builds a 2-dimensional array using the "type" and "color" for the dimensions.

Once the rows have all been passed and the counts accumulated, the last bit of code would start the "top" of the array and present the grid of totals.
Back to top
View user's profile Send private message
Alan Voss

New User


Joined: 29 Nov 2006
Posts: 32
Location: Jacksonville, FL

PostPosted: Fri Mar 23, 2007 10:08 pm
Reply with quote

Perhaps this is ugly, and it only works if you know all possible values for COLOUR before hand:
select type,
sum (case colour
when 'YELLOW' then 1 else 0 end) as Yellow,
sum (case colour
when 'RED' then 1 else 0 end) as RED,
sum (case colour
when 'BLUE' then 1 else 0 end) as BLUE,
sum (case colour
when 'GREY' then 1 else 0 end) as GREY,
sum (case colour
when 'WHITE' then 1 else 0 end) as WHITE,
sum (case colour
when 'GREEN' then 1 else 0 end) as GREEN
from table
group by type
order by type;
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
No new posts XDC SDSF output to temp dataset CLIST & REXX 4
Search our Forums:

Back to Top