--------------6CEAFC2BC2D1B3FCA6D2BB02
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Adrian Galindo ha scritto:
> Hola lista. Aqui de regreso....
>
> Una pregunta tal vez medio obvia y novatona:
>
> Con distinct selecciono los registros sin duplicar, los repetidos no los
> regresa... como le hago para que solo me muestre los repetidos??
>
La tabla contiene los seguientes datos; y yo quiero saber quantos tienen lo
mismo apellido:
apellido          |nombre
----------+-----------------
CANOVA    |ROMANO
CHIUCHIOLO|GIULIANO
CHIUCHIOLO|ANNALISA
JOHANNEY  |GEORGE
JOHANNEY  |MARY
OWUSU     |RICHARD
PREVITI   |ENRICO
PREVITI   |PATRIZIA
PREVITI   |VALERIO
(9 rows)
select APELLIDO from FAMILIA group by APELLIDO having count (APELLIDO) > 1;
apellido
-------------------
CHIUCHIOLO
JOHANNEY
PREVITI
(3 rows)
En SQL92 se puede hacer asi:
select * from FAMILIA where APELLIDO in (
    select APELLIDO from FAMILIA group by APELLIDO having count (APELLIDO) >
1;
);
pero PostgreSQL tiene un bug en HAVING por eso tienes de hacerlo en dos
fases:
- Jose' -
And behold, I tell you these things that ye may learn wisdom; that ye may
learn that when ye are in the service of your fellow beings ye are only
in the service of your God.                - Mosiah 2:17 -
--------------6CEAFC2BC2D1B3FCA6D2BB02
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
 
Adrian Galindo ha scritto:
Hola lista. Aqui de regreso....
Una pregunta tal vez medio obvia y novatona:
Con distinct selecciono los registros sin duplicar, los repetidos no
los
regresa... como le hago para que solo me muestre los repetidos??
 
La tabla contiene los seguientes datos; y yo quiero saber quantos tienen
lo mismo apellido:
apellido          |nombre
----------+-----------------
CANOVA    |ROMANO
CHIUCHIOLO|GIULIANO
CHIUCHIOLO|ANNALISA
JOHANNEY  |GEORGE
JOHANNEY  |MARY
OWUSU     |RICHARD
PREVITI   |ENRICO
PREVITI   |PATRIZIA
PREVITI   |VALERIO
(9 rows)
 
select APELLIDO from FAMILIA group by APELLIDO having count (APELLIDO)
> 1;
apellido
-------------------
CHIUCHIOLO
JOHANNEY
PREVITI
(3 rows)
En SQL92 se puede hacer asi:
select * from FAMILIA where APELLIDO in (
    select APELLIDO from FAMILIA group by APELLIDO
having count (APELLIDO) > 1;
);
pero PostgreSQL tiene un bug en HAVING por eso tienes de hacerlo
en dos fases:
- Jose' -
And behold, I tell you these things that ye may learn wisdom; that
ye may
learn that when ye are in the service of your fellow beings ye
are only
in the service of your God.               
- Mosiah 2:17 -