Tema: Subconsultas
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/05/2011, 15:06
leonardo_josue
Colaborador
 
Fecha de Ingreso: enero-2007
Ubicación: México
Mensajes: 2.097
Antigüedad: 17 años, 4 meses
Puntos: 447
Respuesta: Subconsultas

Hola Marrselo:

Tú mism@ nos diste la respuesta:

Cita:
( hacer un SUM(monto) from pagos where id <"que el id actual")
Código MySQL:
Ver original
  1. mysql> select id, total, cuota,
  2.     -> ifnull((select sum(total) from pagos T2
  3.     -> where T2.id < T1.id), 0) calculado
  4.     -> from pagos T1;
  5. +-----+-------+-------+-----------+
  6. | id  | total | cuota | calculado |
  7. +-----+-------+-------+-----------+
  8. |  21 | 50.00 |     1 |      0.00 |
  9. |  22 | 50.00 |     2 |     50.00 |
  10. |  23 | 50.00 |     3 |    100.00 |
  11. |  45 | 20.00 |     4 |    150.00 |
  12. |  67 | 10.00 |     4 |    170.00 |
  13. |  88 |  5.50 |     4 |    180.00 |
  14. |  91 | 14.50 |     4 |    185.50 |
  15. | 102 | 50.00 |     5 |    200.00 |
  16. | 110 | 50.00 |     6 |    250.00 |
  17. +-----+-------+-------+-----------+
  18. 9 rows in set (0.45 sec)

Saludos
Leo.