Hola
Yo estoy de acuerdo con Casimiro, hay que obtener el precio de la última fecha. A ver si esto funciona para lo que deseas.
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 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