select a.descripcio,a.codigo,max(a.fecha),
avg((select a.precio from lineas where codigo=a.codigo and cliente=:cliente
and fecha=(select max(fecha) from lineas where codigo=a.codigo and cliente=:cliente)))
from lineas a
where a.cliente=:cliente
group by a.descripcio,a.codigo