2012/8/27 Aland Laines <aland.lai...@gmail.com>:
>
> Tengo una tabla con los campos
>
> UBIGEO, REGION, PROVINCIA, DISTRITO, TIPO
>
> el campo tipo puede ser 'R', 'P', o 'D'.
>
> Lo que nesecito hacer es una vista a partir de esa tabla, que me cuente por
> REGION cuantas R, P o D.
>

SELECT region,
              sum(case tipo when 'R' then 1 else 0 end) 'R',
              sum(case tipo when 'P' then 1 else 0 end) 'P',
              sum(case tipo when 'D' then 1 else 0 end) 'D'
   FROM TABLA
 GROUP BY 1;

-- 
Jaime Casanova         www.2ndQuadrant.com
Professional PostgreSQL: Soporte 24x7 y capacitación

-
Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda@postgresql.org)
Para cambiar tu suscripción:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

Responder a