Ver Mensaje Individual
  #17 (permalink)  
Antiguo 01/08/2011, 10:55
emiajsiul
 
Fecha de Ingreso: julio-2011
Mensajes: 12
Antigüedad: 12 años, 9 meses
Puntos: 0
Respuesta: Operacion con campo anterior de una columna

OK GRACIAS, pues ya metido en esto, estoy aplicando aplicando este codigo:
Código MySQL:
Ver original
  1.             VN_UNIDAD UNIDAD,
  2.             KM,
  3.             LITROS,
  4.             IF(@kml=0, @kml:=KM, @kml)km1,
  5.                         (KM-@kml)*(-1) RECORRIDO,
  6.                         (@kml:= KM) km2
  7.                         FROM VALES
  8.                                  WHERE VN_UNIDAD = 'DR 031'
  9. LIMIT 10;

funciona muy bn solo me falta inicializar @km1:=0 por el siguiente detalle:

Código MySQL:
Ver original
  1. DR 031  262522.000  37.575  260025  -2497   262522.000
  2. DR 031  262245.000  35.388  262522  277 262245.000
  3. DR 031  261911.000  43.668  262245  334 261911.000
  4. DR 031  261504.000  33.349  261911  407 261504.000
  5. DR 031  261253.000  43.668  261504  251 261253.000

El primer registro hace una resta de un valor desconocido y los valores reales inician en la siguiente linea