SQL: Avoid repeating row and sum values

1

I have this select:

select 
  DISTINCT (clients.name) as nomeempresa, 
  payments.amount_paid as pagamento, 
  receipts.original_amount as recebimento
FROM 
  payments, 
  receipts, 
  receipt_status, 
  payment_status, 
  clients
WHERE 
  payments.id = payment_status.id AND
  receipts.id = receipt_status.id AND
  clients.id = payments.client_id AND
  clients.id = receipts.client_id AND
  payments.created_at < CURRENT_DATE AND payments.created_at > CURRENT_DATE-1 OR 
  receipts.created_at < CURRENT_DATE AND receipts.created_at > CURRENT_DATE-1
 GROUP BY
  nomeempresa, pagamento, recebimento

But the output:

I have to filter the output and show the total in the next column.

    
asked by anonymous 30.10.2017 / 17:48

1 answer

1

I was able to get the result with a command line:

SUM( receipts.original_amount) 

Complete answer:

select 
  DISTINCT (clients.name) as nomeempresa, 
  SUM (payments.amount_paid) as pagamento, 
  SUM (receipts.original_amount)  as recebimento
    
30.10.2017 / 22:04