title: PostgreSQL: Put the values in one column as header in result set?
body: <p>Let's say I have two tables, one with schools and one with classes. Both tables have SchoolID so they can be matched. They look something like this:</p>
  
  <p>TableSchools</p>
  
  <pre><code>SchoolID SchoolName
  1        SchoolOne
  2        SchoolTwo
  3        SchoolThree
  </code></pre>
  
  <p>TableClasses</p>
  
  <pre><code>ClassID SchoolID ClassName
  1       1        ClassOne
  2       1        ClassTwo
  3       2        ClassThree
  4       2        ClassFour
  5       2        ClassFive
  6       3        ClassSix
  7       3        ClassSeven
  </code></pre>
  
  <p>and I want my resultset to be like this</p>
  
  <pre><code>SchoolOne   SchoolTwo   SchoolThree
  ClassOne    ClassThree  ClassSix
  ClassTwo    ClassFour   ClassSeven
  NULL        ClassFive   NULL
  </code></pre>
  
  <p>I've heared in TSQL I could use <code>group by with rollup</code> but it seems that's not possible or at least I don't understand how to use it <a href="https://www.postgresql.org/docs/devel/static/queries-table-expressions.html" rel="nofollow">from here</a>.</p>