title: Is there a way to select a "dynamic" column based on LEFT JOIN?
body: <p>I have a query that looks like this:</p>
  <pre><code>SELECT
     cid,
     COALESCE(newcust.newcust, false) AS newcust,
     COALESCE(svipstat.svipstat, false) AS svipstat,
     COALESCE(vipstat.vipstat, false) AS vipstat
  FROM customer c
  LEFT JOIN (
      SELECT cid, true AS newcust
      FROM customer c
      WHERE active IS TRUE AND created_at &gt;= current_date - interval '1 day' * 30
  ) AS newcust ON newcust.cid = c.cid
  LEFT JOIN (
      SELECT cid, true AS svipstat
      FROM customer c
      WHERE active IS TRUE AND (select count(1) from visits where cid = customer.cid and vdate &gt;= current_date - interval '30 days') &gt;= (SELECT value FROM criteria WHERE c = 'svipstat' AND criteria.pid = c.pid)
  ) AS svipstat ON svipstat.cid = c.cid
  LEFT JOIN (
      SELECT cid, true AS vipstat
      FROM customer c
      WHERE active IS TRUE AND (select count(1) from visits where cid = customer.cid and vdate &gt;= current_date - interval '30 days') &gt;= (SELECT value FROM criteria WHERE c = 'vipstat' AND criteria.pid = c.pid)
  ) AS vipstat ON vip.cid = c.cid;
  </code></pre>
  <p>What this query returns, is something like this:</p>
  <pre><code>cid | newcust |  svip | vipstat
  --------------------------------
  1.     true.     false.    false
  2.    false.    true.      false
  3.    false.    false.     true
  </code></pre>
  <p>My ideal scenario, would be if I can have a column return a &quot;string&quot;, based on the LEFT JOINS I have, for example:</p>
  <pre><code>cid | status
  -------------
  1.    newcust
  2.    svip
  3     vipstat
  </code></pre>
  <p>Is there a way to achieve this??? I've been having a hard time trying to find a solution :(</p>