title: If exists ... else clause in SQLite
body: <p>I have a db and need to extract some data from it for use in a python script. I'm new to sql and just know the basics.<br>
  This is what I want to do:</p>
  
  <pre><code>if exists (
  select date, sum(amount) 
  from transactions 
  where category = 'Food' 
  group by date
  ) 
  else 
  select date, 0
  </code></pre>
  
  <p>For all dates present in <code>transaction</code> table, I want to get <em>date</em>, <em>sum(amount)</em> for category <em>Food</em>. If there are no transactions with category <em>Food</em> I want to get <em>date</em>, <em>0</em> (since <em>sum(amount)</em> of <em>Food</em> that day is 0).  </p>
  
  <p>The code I currently have is</p>
  
  <pre><code>select date, sum(amount) 
  from transactions 
  where category = 'Food' 
  group by date
  </code></pre>
  
  <p>but it doesn't contain the <em>date</em>, <em>0</em> rows for dates which don't have any <em>Food</em> transactions.  </p>
  
  <p>How should I rewrite this to make it work?  </p>
  
  <p><strong>I have read <a href="https://stackoverflow.com/questions/7746306/sqlite-if-exists-clause">this</a> question, but the answer there is exclusive to boolean data, doesn't provide enough details and can't be generalized.</strong></p>