Ver Mensaje Individual
  #4  
Antiguo 04-11-2008
Avatar de droguerman
droguerman droguerman is offline
Miembro
 
Registrado: abr 2005
Ubicación: tierra
Posts: 999
Reputación: 22
droguerman Va por buen camino
Con tablas temporales, (falta probar):
Código SQL [-]
Create table #t
(
fecha smalldatetime,
precio decimal(10,2),
grupo int
);
INSERT INTO #t(fecha, precio, grupo)
  SELECT fecha, precio, 0 FROM tabla ORDER BY fecha;

DECLARE @oldPrecio DECIMAL(10,2);
DECLARE @grupo int;
SET @oldPrecio = -1; --valor que no existe 
SET @grupo=0;
UPDATE #t set @grupo= grupo=(CASE WHEN @oldPrecio=precio THEN @grupo ELSE @grupo+1 END), @oldPrecio=precio=precio;
SELECT grupo, min(Fecha), max(Fecha), AVG(precio) FROM #t GROUP BY grupo;
__________________
self.free;
Responder Con Cita