title: How to use aggregate functions in mysql?
body: <p>I have 2 tables<br/></p>
  
  <ol>
  <li>students</li>
  <li>payments</li>
  </ol>
  
  <p>In students table I have fields like </p>
  
  <pre><code>student_id(Primary key),
  student_name, 
  student_university, 
  student_counselor
  </code></pre>
  
  <p>In payments table I have fields like </p>
  
  <pre><code>payment_id(Primary key),
  student_id(Foreign key reference to students table), 
  payable,
  paid, 
  balance
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pyTwW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pyTwW.png" alt="enter image description here"></a></p>
  
  <p>I am trying to achive:</p>
  
  <ul>
  <li>Display the result in the form below i.e each counselor has their students in different university.</li>
  <li>The total number of students belongs to particular university from particular counselor and how much amount is payable, paid and balance as shown in the table above. </li>
  </ul>
  
  <p>Any insight?</p>