title: PL/SQL SUM Difference Example
body: <p>I'm trying to implement this SQL code in PL/SQL</p>
  
  <p>SQL Code:</p>
  
  <pre><code>select  SUM(SUM(distinct inv_total) - SUM(distinct credit_total) ) as TOTAL from invoice
  where cus_id =95 
  group by inv_total, credit_total
  </code></pre>
  
  <p>PL/SQL Code: </p>
  
  <pre><code>Declare 
  
  total invoice.inv_total%TYPE;
  cust_id NUMBER := 95;
  BEGIN
  
  select  SUM(SUM(distinct inv_total) - SUM(distinct credit_total) ) 
  INTO total from invoice
  where cus_id= cust_id;
  dbms_output.put_line('Total is ' || total);
  
  END;
  
  ERROR at line 1: 
  ORA-00978: nested group function without GROUP BY 
  ORA-06512: at line 8 
  </code></pre>
  
  <p>Any tips how to use GROUP BY with PL/SQL?
  Thank you</p>