Ver Mensaje Individual
  #8  
Antiguo 02-09-2004
Avatar de guillotmarc
guillotmarc guillotmarc is offline
Miembro
 
Registrado: may 2003
Ubicación: Huelva
Posts: 2.638
Reputación: 24
guillotmarc Va por buen camino
Hola.

La consulta más o menos va a ser :

select
(select max(TOPE) from TABLA1_MARCAS where MARCA = 'CAJAS 44' and GRUPO = 'CARTON') as MAX_TOPE,
(select max(TOPELISTA) from TABLA1_MARCAS where MARCA = 'CAJAS 44' and GRUPO = 'CARTON') as MAX_TOPELISTA,
(select max(TOPEMAY) from TABLA1_MARCAS where MARCA = 'CAJAS 44' and GRUPO = 'CARTON') as MAX_TOPEMAY,
(select min(TOPE) from TABLA1_MARCAS where MARCA = 'CAJAS 44' and GRUPO = 'CARTON') as MIN_TOPE,
(select min(TOPELISTA) from TABLA1_MARCAS where MARCA = 'CAJAS 44' and GRUPO = 'CARTON') as MIN_TOPELISTA,
(select min(TOPEMAY) from TABLA1_MARCAS where MARCA = 'CAJAS 44' and GRUPO = 'CARTON') as MIN_TOPEMAY
from RDB$DATABASE

Como ha dicho Xavi tienes 6 subconsultas, y tienes que crear 3 índices : MARCA + GRUPO + TOPE, MARCA + GRUPO + TOPELISTA, MARCA + GRUPO + TOPEMAY para que sea completamente eficaz.

NOTA: Dado que solo hay que retornar una fila, he basado la consulta principal en la tabla RDB$DATABASE, que es una tabla de sistema, que sabemos que siempre existe y siempre devuelve un solo registro. (Aunque podrias haber utilizado cualquier tabla tuya, que sepas seguro que siempre contiene un único registro).

Saludos.
__________________
Marc Guillot (Hi ha 10 tipus de persones, els que saben binari i els que no).
Responder Con Cita