title: Is there an `if` syntax in SQL?
body: <p>I am looking for a solution to the following:</p>
  
  <ol>
  <li><p>Go in to the <code>users</code> table and find a user who has listed items on the site.  In this <code>users</code> table, there is no column about auctions.  Instead, it is connected to an <code>accounts</code> table with a key (in <code>accounts</code>, this column is called <code>user</code>), so I used this to join them: </p>
  
  <pre><code>SELECT users.id ,accounts.user FROM users
  LEFT JOIN accounts
  ON users.id = accounts.user
  WHERE accounts.user IS NOT NULL 
  </code></pre></li>
  <li><p>From these IDs (users which have listed items for auction), I need to find their account balance.  This is also in the <code>accounts</code> table.  The balance is contained in a column called <code>operation_amount</code>.  I also have another column called <code>operation_type</code> which describes whether a user has a positive or negative balance.  For example, if <code>operation_type = 1</code>, he has a negative balance, while if <code>operation_type = 2</code>, he has a positive balance.</p></li>
  </ol>
  
  <p>Now I have another table called <code>tmpinvoice</code> where there is a column called <code>amount</code>.  This shows how much in fees a user needs to pay to the site administrators. </p>
  
  <p>Given this, I need to calculate how much he must pay in total.  For example, if a user has a $200 balance, I need to check whether it's negative or positive based on the <code>operation_type</code>.</p>
  
  <p>Imagine a scenario where <code>balance - fees = total</code>, like <code>200 - 0.25 = ?</code>.  In this case, the amount calculated will be different based on whether the <code>200</code> is positive or negative.</p>
  
  <p>I hope this is a better description.</p>