Q:

Erro ao executar query no PostgreSQL

Apos executar essa query:
SELECT  
  p.name as nomerecebe,
  r.created_at as datarecebimento,
  r.original_amount as valorboleto,
  rs.name as statusr,
  SUM(r.original_amount) as total  
FROM 
  people as p,
  receipts as r,
  receipt_status as rs 
WHERE 
  p.id = r.person_id AND r.id = rs.id AND
  r.created_at < CURRENT_DATE AND r.created_at > CURRENT_DATE -199
GROUP BY 
    nomerecebe, datarecebimento, valorboleto, statusr, total

Recebo esta mensagem de erro: 

ERROR:  aggregate functions are not allowed in GROUP BY LINE 6:  
SUM(r.original_amount) as total  
      ^

********** Error **********

ERROR: aggregate functions are not allowed in GROUP BY SQL state:
42803 Character: 129

A:

Esse erro está te dizendo que funções como o SUM não podem ser colocadas dentro do GROUP BY.
Tente rodar o código assim:
SELECT  
  p.name as nomerecebe,
  r.created_at as datarecebimento,
  r.original_amount as valorboleto,
  rs.name as statusr,
  SUM(r.original_amount) as total  
FROM 
  people as p,
  receipts as r,
  receipt_status as rs 
WHERE 
  p.id = r.person_id AND r.id = rs.id AND
  r.created_at < CURRENT_DATE AND r.created_at > CURRENT_DATE -199
GROUP BY 
    nomerecebe, datarecebimento, valorboleto, statusr

