Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: tricky SQL
bcjm wrote:
> I have a table with 3 columns: Person, Class and grade. There are
> unlimited number of classes available but each person can only take 3
> classes max. How do you right one SQL to show the list of class and
> grade of each person in one row?
>
> Example: Table T
>
> p1 c1 A
> p1 c2 D
> p1 c3 B
> p2 c5 B
> p3 C1 A
> p3 C8 C
> ...
> ...
>
> SQL result
> P1 C1 A C2 D C3 B
> P2 C5 B
> P3 C1 A C8 C
http://www.psoug.org
click on DECODE
search for cross-tabbing with DECODE which can also be done with CASE.
And yes you should have paid more attention in class when it was discussed. ;-)
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace 'x' with 'u' to respond)Received on Thu Mar 03 2005 - 10:23:33 CST