title: PostgreSQL view embedded if-statements
body: <p>In my database, for stores that have no rating from Reseller Ratings, they still have an entry but have <code>-1.0</code> instead of a number between <code>0.0</code> and <code>10.0</code>. The following query results in <code>-10.00</code> showing up in my view for those stores with <code>-1.0</code>. Instead, I would like either nothing or a <code>-</code> showing up in its place, but I'm not very comfortable with implementing embedded if-statements in my view. Here is my current view.</p>
  
  <pre><code>CREATE VIEW myview AS
  SELECT co_url_name AS company_url, score_combined AS stella_score, trunc(score*10, 2) AS bizrate_score,
  (SELECT trunc("lifetimeRating"*10, 2)) AS resellerRating_score
      FROM ss_profile_co AS s LEFT OUTER JOIN "resellerRatings_ratings" AS r
          ON s.id = r.company_id
              LEFT OUTER JOIN (SELECT * FROM bizrate_bizrate_ratings WHERE score_name = 'Overall rating') AS b
                  ON s.id = b.fk_co_id
                      ORDER BY co_url_name ASC;
  </code></pre>
  
  <p>The line <code>(SELECT trunc("lifetimeRating"*10, 2)) AS resellerRating_score</code> is the one that returns the negative numbers (or, for valid entries, will return a score between <code>0.00</code> and <code>100.00</code>). </p>
  
  <p>Obviously, I could simply remove these entries from the database that result in this, but it's half a learning experience and half out of my hands to do so anyways.</p>
  
  <p>I appreciate the help!</p>
  
  <p>EDIT: Attempted an embedded if but not surprisingly got an error.</p>
  
  <pre><code>IF (SELECT trunc("lifetimeRating"*10, 2)) = -10.00 THEN NULL ELSE (SELECT trunc("lifetimeRating"*10, 2)) AS resellerRating_score
  </code></pre>
  
  <p>EDIT2: Figured it out. Line in question is as follows:</p>
  
  <pre><code>(SELECT trunc("lifetimeRating"*10, 2) WHERE trunc("lifetimeRating"*10, 2) &gt; 0) AS resellerrating_score
  </code></pre>
  
  <p>/foreveralone</p>