title: View - Return 0 if no rows found in a grouped by query
body: <p>Let's say I have the following MySQL view:</p>
  
  <pre><code>create or replace view total_transactions(account_id, total) as
  select
    t.account_id,
    ifnull(sum(t.value), 0) as total
  from transactions t
  where t.paid IS TRUE
  group by t.bank_account_id;
  </code></pre>
  
  <p>Let's say the account doesn't have any transaction yet, I want the view to return 0.
  Right now, if I do a select like:</p>
  
  <pre><code>select * from total_transactions where account_id = 2060;
  </code></pre>
  
  <p>And account 2060 didn't had any transaction, it will return me nothing, instead of 0.</p>
  
  <p>How could I fix that?</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <h1>EDIT</h1>
  
  <p>I think it could be something with the <code>group by</code>...</p>
  
  <p>If I execute the query that I'm using for the view without the group by, it works (return 0 even with no results), but if I use <code>group by</code> it comes null:</p>
  
  <pre><code>select
    t.account_id,
    ifnull(sum(t.value), 0) as total
  from transactions t
  where t.paid IS TRUE
  and account_id = 2060;
  </code></pre>
  
  <p>Returns <code>0</code>, and</p>
  
  <pre><code>create or replace view total_transactions(account_id, total) as
  select
    t.account_id,
    ifnull(sum(t.value), 0) as total
  from transactions t
  where t.paid IS TRUE
  and account_id = 2060
  group by t.bank_account_id;
  </code></pre>
  
  <p>Return an empty set.</p>