Re: pivoting, crosstabbing and almost there ! - Mailing list pgsql-general

From Stephan Szabo
Subject Re: pivoting, crosstabbing and almost there !
Date
Msg-id 20020725121958.X50051-100000@megazone23.bigpanda.com
Whole thread Raw
In response to pivoting, crosstabbing and almost there !  (robert kraus <rob_kra@yahoo.com>)
List pgsql-general

> I am trying to get a pivoted result from a query. The
> pivoting works, however I want to eliminate
> some of the rows, which have no value at all in every
> column but the name column.

Maybe something like:

SELECT * from (
 SELECT students.name,
      ( SELECT score FROM scores
     WHERE (
         students.name = scores.name
         AND
         scores.exam  = 'first'
         AND
         scores.score > '70'
         )
     ) AS first,
     ( SELECT score FROM scores
     WHERE (
         students.name = scores.name
         AND
         scores.exam  = 'second'
         AND
         scores.score > '80'
         )
     ) AS second,
     ( SELECT score FROM scores
     WHERE (
         students.name = scores.name
         AND
         scores.exam  = 'third'
         AND
         scores.score > '90'
         )
     ) AS third
 FROM students
) AS c
where c.first is not null or c.second is not null or
 c.third is not null;



pgsql-general by date:

Previous
From: robert kraus
Date:
Subject: pivoting, crosstabbing and almost there !
Next
From: Andrew Sullivan
Date:
Subject: archives dead again?