Ver Mensaje Individual
  #9 (permalink)  
Antiguo 09/03/2010, 09:15
cce
 
Fecha de Ingreso: junio-2009
Mensajes: 92
Antigüedad: 15 años, 6 meses
Puntos: 0
Respuesta: secuencia select anidadas en postgresql¿

Te muestro otras dos tablas similares con las que no me sale, solo me da el ultimo elemento:

Tabla «public.ra»
Columna | Tipo | Modificadores
---------+-----------------------------+---------------
id | smallint | not null
fchl | timestamp without time zone | not null
dmn | character varying(12) |
nchs | character varying(25) |
nmtr | character varying(25) |
mrc | character varying(20) |
mdl | character varying(20) |
clr | character varying(15) |
nf12 | character varying(20) | not null
nyat | character varying(30) | not null
dnit | character varying(15) | not null
nccd | character varying(30) | not null
fch | character varying(10) |
idp | smallint | not null
idpv | smallint | not null
bsvs | text |
tp | character varying(1) |
Índices:
«ra_pkey» PRIMARY KEY, btree (id, idp, idpv, fchl)



Tabla «public.hcv»
Columna | Tipo | Modificadores
---------+-----------------------------+------------------------
id | smallint | not null
idm | integer |
tv | character varying(25) |
rcm | character varying(25) |
m | character varying(25) |
fchl | timestamp without time zone | not null default now()
Índices:
«hcv_pkey» PRIMARY KEY, btree (id, fchl)


select * from hcv;

id | idm | tv | rcm | m | fchl
----+--------+--------------+----------------+------------------+----------------------------
40 | | automovil | | | 2010-03-04 09:58:37.942077
40 | 401052 | motovehiculo | 23479872348923 | 23479872348923 | 2010-03-04 10:01:39.543915
40 | 404233 | automovil | 777 | 8798789798789789 | 2010-03-04 09:58:21.990037
40 | | automovil | 756765756 | | 2010-03-08 08:51:32.91414
(4 filas)


select * from ra;

id | fchl | dmn | nchs | nmtr | mrc | mdl | clr | nf12 | nyat | dnit | nccd | fch | idp | idpv | bsvs | tp
----+---------------------+-----------+--------------------+-----------------+----------+---------+-----------------+--------------------+--------+------------+---------------------+------------+-----+------+-----------------------------------------------------------------------------------+----
1 | 2010-01-11 11:39:00 | 0000 | 34545gsdfg344 | 2308923 | Ford | Ka | blanco-celeste | 3453453453454 | C | 26.150.146 | 308974894fh39283892 | 11/01/2010 | 1 | 1 | Posee faro trasero roto.--ademas no tiene rueda d auxilio.- |
40 | 2010-02-04 08:30:58 | XXXXQQQQ | 7r6u7rng6y876 | 5688ighjk | ghjkgdhj | ghfgh | bbbbb | 756765756 | ccc | 55645645 | hgfgh | 28/01/2010 | 1 | 1 | ninguna.-| M
1 | 2010-01-14 09:49:24 | 324sdgf | 3328923892389eh392 | 2309409dhf34902 | boing | 707b | blanco-celeste | 328934e38 | a | 2368945362 | 303023dhehd38239 | 08/01/2010 | 1 | 1 | ninguna.- | A
40 | 2010-02-10 09:35:54 | 345dfgdfg | 38r78dsvfu493 | 43r7dfbjh | skdbv | sv isdb | blanco | 9348 ty9rt49yr4934 | tttt | 3333245 | 3459834r594 | 10/02/2010 | 51 | 4 | weiegif | M
40 | 2010-03-04 09:58:26 | aaa777 | 789798hjg7868898 | 98679787bg7ty79 | pika | II | blanca y celest | 8798789798789789 | c.c.e. | 26.150.146 | 68666977798798 | 14/01/2010 | 1 | 1 | nfgfdg | V
(5 filas)

SELECT dmn, nf12 FROM ra INNER JOIN hcv AS hcv ON nf12 = rcm WHERE hcv.fchl::date BETWEEN '2010-02-01' AND '2010-05-31';

dmn | nf12
--------+-----------
XXXXQQQQ | 756765756
(1 fila)