Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined # of column output

Status
Not open for further replies.

luminary

Programmer
May 30, 2002
1
US
I'm looking for a way to do the following in SQL.

Let's say we have 3 columns on a table (a, b, c). There is an undefined number of c's per each a, b grouping. If I do a simple select off of the table, I'll get one row of output per each a - b - c combination:

a1 b1 c1
a1 b1 c2
a1 b2 c1
a2 b1 c1
a2 b1 c2
a2 b1 c3

What I need, is to get is one row of output per each a b combination:

a1 b1 c1 c2
a1 b2 c1
a2 b1 c1 c2 c3

Any thoughts?
 
If you have a reasonably limited number of 'c' type values, you can accomplish it with the following:

Select a, b,
Min(case when c = 'c1' then 'c1' else NULL end),
Min(case when c = 'c2' then 'c2' else NULL end),
Min(case when c = 'c3' then 'c3' else NULL end) etc
From Table1
Group by a, b


If you have a boatload of values for column 'c', then this would be tough to implement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top