Condition in a calculated field - Mailing list pgsql-novice

From JORGE MALDONADO
Subject Condition in a calculated field
Date
Msg-id CAAY=A78wDyHXXbZGZtL5TcHwcXzUEkCUgezK22Nj7=nV4Mi_8A@mail.gmail.com
Whole thread Raw
Responses Re: Condition in a calculated field  (David G Johnston <david.g.johnston@gmail.com>)
List pgsql-novice
Can I use a calculated field in a WHERE condition of a SELECT statement? I get a "column 'total' does not exist" error when I run the statement below. 'total' is a field generated by a SUM and I want to use it in the WHERE condition.

SELECT 
  facturas.fce_id,
  facturas.fce_numero_factura,
  facturas.fce_fecha,
  compradores.com_nombre,
  facturas.fce_subdivision,
  facturas.fce_valor_comercial,
  SUM(facsub.fce_valor_comercial) AS total
FROM
  trafico.facturas_exportacion facturas
  INNER JOIN trafico.cat_compradores compradores ON (facturas.fce_comprador = compradores.com_clave)
  INNER JOIN trafico.facturas_exportacion facsub ON (facturas.fce_id = facsub.fce_id_factura_original)
WHERE
  facturas.fce_subdivision = true AND facturas.fce_valor_comercial > total
GROUP BY facturas.fce_id,compradores.com_clave

Respectfully,
Jorge Maldonado

pgsql-novice by date:

Previous
From: Francisco Tolmasky
Date:
Subject: Re: Compiling for iOS
Next
From: David G Johnston
Date:
Subject: Re: Condition in a calculated field