title: How to use a sum (case) into second table as condition
body: <p>This is my query: </p>
  
  <pre><code>    select matricule,nom_ligne,count(num_ticket) as nbre_ticket, sum(prix) as moant,receveur, nom_gie, 
  (SELECT SUM(CASE WHEN depense.id_bus = 1 THEN depense.montant ELSE 0 END) AS NbrARRNP from depense) as tot,
  receveur, nom_gie from journal_recettes
  group by matricule,nom_ligne,receveur, nom_gie
  </code></pre>
  
  <p>And I obtain this results: 
  <a href="http://i.stack.imgur.com/YGd1Q.jpg" rel="nofollow">Results</a>
  But what I need is to use this condition : </p>
  
  <pre><code>CASE WHEN depense.id_bus = journal_recettes.id_bus THEN depense.montant ELSE 0 END
  </code></pre>
  
  <p>But When I try, i obtain this error :</p>
  
  <p><a href="http://i.stack.imgur.com/skGcD.jpg" rel="nofollow">Error</a></p>