View previous topic :: View next topic
|
Author |
Message |
baidyanath_biswas
New User
Joined: 04 Sep 2006 Posts: 11
|
|
|
|
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 |
|
|
mkk157
Active User
Joined: 17 May 2006 Posts: 310
|
|
|
|
Hi baidyanath_biswas,
Here u r trying to make the fields into columns. I believe it is not possible. |
|
Back to top |
|
|
vini_srcna
Active User
Joined: 26 May 2005 Posts: 178 Location: Copenhagen, Denmark
|
|
|
|
Think you have to do RND on this. |
|
Back to top |
|
|
Prajesh_v_p
Active User
Joined: 24 May 2006 Posts: 133 Location: India
|
|
|
|
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 |
|
|
baidyanath_biswas
New User
Joined: 04 Sep 2006 Posts: 11
|
|
|
|
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 |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Alan Voss
New User
Joined: 29 Nov 2006 Posts: 32 Location: Jacksonville, FL
|
|
|
|
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 |
|
|
|