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
 

 

Using Sql queries, is a output like this possible

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Using Sql queries, is a output like this possible
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    Post subject: Re: formatted output
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    Post subject:
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    Post subject:
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    Post subject: Any further help??
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

Site Director


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

PostPosted: Fri Mar 23, 2007 8:03 pm    Post subject:
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    Post subject:
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    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 Incorrect output when trying to add n... monica1 PL/I & Assembler 10 Fri Jan 13, 2017 5:02 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm
No new posts Syncsort - Hard coded Value in output PORYES SYNCSORT 1 Thu Nov 03, 2016 9:23 am
No new posts output data in CSV Format janmejay COBOL Programming 8 Sat Oct 15, 2016 2:20 pm
This topic is locked: you cannot edit posts or make replies. output data in CSV Format janmejay DFSORT/ICETOOL 3 Sat Oct 15, 2016 2:16 pm


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