Ver Mensaje Individual
  #11  
Antiguo 01-12-2012
[egostar] egostar is offline
Registrado
 
Registrado: feb 2006
Posts: 6.557
Reputación: 25
egostar Va camino a la fama
Ahora que lo veo nuevamente, me parece que me ha faltado un detalle importante.

Código SQL [-]
Select 
   Max(Codclient) as Codclient, 
   Max(Fecha) as Fecha,
   Producto, 
   Sum(Unidades) as Unidades,
   Max(Precio) as Precio, 
   Sum(Subtotal) as Subtotal, 
   Avg(Precio) as PMedio, 
   Min(Precio) as MPrecio,
   (select first 1 X.precio from LineasVentas X 
    where X.Codclient = :C And 
          X.Fecha between :F1 and :F2 And
          X.Producto = Producto  
    order by X.fecha desc) as UltimoP
   
from LineasVentas
Where Codclient = :C And Fecha between :F1 and :F2
Group By Producto
Having Sum(Unidades) <> 0
Order by Producto

Saludos
__________________
"La forma de empezar es dejar de hablar y empezar a hacerlo." - Walt Disney
Responder Con Cita