Tema: Consulta SQL
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/04/2007, 14:52
Avatar de Andres95
Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 5 meses
Puntos: 38
Re: Consulta SQL

Que tal algo asi...
Código:
Select Top 1 
       T.Codigo_Producto
      ,T.Precio
From (Select Top 1
             Codigo_Producto
            ,max(Fecha_Venta) Fecha_Venta 
      From  #tmp1   T
      Where  Fecha_Venta between @FechaInicial And @FechaFinal
      Group by 
            Codigo_Producto       
      Order by
            SUM (Unidades_Facturadas)  Desc) P    -- Producto mas vendido, y su ultima fecha de venta...
Inner join
      #tmp1 T
On   P.Codigo_Producto = T.Codigo_Producto  And
     P.Fecha_Venta  = T.Fecha_Venta 
Order by 
     T.Fecha_Venta  Desc -- En caso que sea el mismo dia y que se almacene la hora tambien....
__________________
La sencillez y naturalidad son el supremo y último fin de la cultura...
--
MCTS : SQL Server 2008, .NET Framework 3.5, ASP.NET Applications.