Ver Mensaje Individual
  #3 (permalink)  
Antiguo 19/05/2011, 21:28
tokkaido
 
Fecha de Ingreso: julio-2009
Mensajes: 90
Antigüedad: 14 años, 9 meses
Puntos: 4
Respuesta: obtener la fecha mas reciente

Gracias scooby151 por responder tan pronto, pero lamentablemente no me da resultado tu modificacion, agrego un poco de datos para hacer el ejercicio a quien se tome la molestia:



Código MySQL:
Ver original
  1. SET FOREIGN_KEY_CHECKS=0;
  2. -- ----------------------------
  3. -- Table structure for vehiculos
  4. -- ----------------------------
  5. DROP TABLE IF EXISTS `vehiculos`;
  6. CREATE TABLE `vehiculos` (
  7.   `id_interno` int(10) unsigned NOT NULL AUTO_INCREMENT,
  8.   `numero` varchar(3) COLLATE utf8_spanish_ci NOT NULL,
  9.   `patente` varchar(7) COLLATE utf8_spanish_ci NOT NULL,
  10.   PRIMARY KEY (`id_interno`),
  11.   UNIQUE KEY `id_interno_idx` (`id_interno`) USING BTREE,
  12.   UNIQUE KEY `numero_idx` (`numero`) USING BTREE,
  13.   UNIQUE KEY `patente_idx` (`patente`) USING BTREE
  14. ) ENGINE=InnoDB AUTO_INCREMENT=177 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
  15.  
  16. -- ----------------------------
  17. -- Records
  18. -- ----------------------------
  19. INSERT INTO `vehiculos` VALUES ('1', '27', 'EB95064');
  20. INSERT INTO `vehiculos` VALUES ('2', '58', 'SU2124K');
  21. INSERT INTO `vehiculos` VALUES ('4', '60', 'TB39596');
  22. INSERT INTO `vehiculos` VALUES ('10', '61', 'TA45354');
  23. INSERT INTO `vehiculos` VALUES ('11', '62', 'TJ97006');
  24. INSERT INTO `vehiculos` VALUES ('12', '66', 'TV9895K');
  25. INSERT INTO `vehiculos` VALUES ('95', '59', 'TB39588');

Código MySQL:
Ver original
  1. SET FOREIGN_KEY_CHECKS=0;
  2. -- ----------------------------
  3. -- Table structure for neumaticos_inventario
  4. -- ----------------------------
  5. DROP TABLE IF EXISTS `neumaticos_inventario`;
  6. CREATE TABLE `neumaticos_inventario` (
  7.   `id_interno` int(10) unsigned NOT NULL AUTO_INCREMENT,
  8.   `codigo` smallint(11) unsigned DEFAULT NULL,
  9.   `prof_ext_inicial` decimal(3,1) unsigned NOT NULL,
  10.   `prof_med_inicial` decimal(3,1) unsigned NOT NULL,
  11.   `prof_int_inicial` decimal(3,1) unsigned NOT NULL,
  12.   `kms_inicial` int(11) unsigned NOT NULL,
  13.   PRIMARY KEY (`id_interno`),
  14.   UNIQUE KEY `id_interno_idx` (`id_interno`) USING BTREE,
  15.   UNIQUE KEY `codigo_idx` (`codigo`) USING BTREE
  16.  
  17. -- ----------------------------
  18. -- Records
  19. -- ----------------------------
  20. INSERT INTO `neumaticos_inventario` VALUES ('1', '3251', '15.0', '15.0', '15.0', '99120');
  21. INSERT INTO `neumaticos_inventario` VALUES ('2', '3250', '15.0', '15.0', '15.0', '99120');
  22. INSERT INTO `neumaticos_inventario` VALUES ('3', '3236', '15.0', '15.0', '15.0', '105438');
  23. INSERT INTO `neumaticos_inventario` VALUES ('4', '3287', '15.0', '15.0', '15.0', '105438');
  24. INSERT INTO `neumaticos_inventario` VALUES ('5', '3333', '15.0', '15.0', '15.0', '101000');
  25. INSERT INTO `neumaticos_inventario` VALUES ('6', '3332', '15.0', '15.0', '15.0', '105438');

Código MySQL:
Ver original
  1. SET FOREIGN_KEY_CHECKS=0;
  2. -- ----------------------------
  3. -- Table structure for neumaticos_vehiculos
  4. -- ----------------------------
  5. DROP TABLE IF EXISTS `neumaticos_vehiculos`;
  6. CREATE TABLE `neumaticos_vehiculos` (
  7.   `id_interno` int(10) unsigned NOT NULL AUTO_INCREMENT,
  8.   `id_neumatico` int(11) unsigned NOT NULL,
  9.   `id_vehiculo` int(11) unsigned NOT NULL,
  10.   `posicion` tinyint(6) unsigned NOT NULL,
  11.   PRIMARY KEY (`id_interno`),
  12.   UNIQUE KEY `id_interno` (`id_interno`) USING BTREE,
  13.   UNIQUE KEY `id_neumatico` (`id_neumatico`),
  14.   UNIQUE KEY `id_pos_veh` (`posicion`,`id_vehiculo`),
  15.   KEY `id_vehiculo_idx` (`id_vehiculo`),
  16.   CONSTRAINT `neumaticos_vehiculos_ibfk_1` FOREIGN KEY (`id_neumatico`) REFERENCES `neumaticos_inventario` (`id_interno`) ON UPDATE CASCADE,
  17.   CONSTRAINT `id_neumatico_vehiculo_fk` FOREIGN KEY (`id_vehiculo`) REFERENCES `vehiculos` (`id_interno`) ON UPDATE CASCADE
  18.  
  19. -- ----------------------------
  20. -- Records
  21. -- ----------------------------
  22. INSERT INTO `neumaticos_vehiculos` VALUES ('1', '1', '95', '1');
  23. INSERT INTO `neumaticos_vehiculos` VALUES ('2', '2', '95', '2');
  24. INSERT INTO `neumaticos_vehiculos` VALUES ('3', '3', '95', '3');
  25. INSERT INTO `neumaticos_vehiculos` VALUES ('4', '4', '95', '4');
  26. INSERT INTO `neumaticos_vehiculos` VALUES ('5', '5', '95', '5');
  27. INSERT INTO `neumaticos_vehiculos` VALUES ('6', '6', '95', '6');


Código MySQL:
Ver original
  1. SET FOREIGN_KEY_CHECKS=0;
  2. -- ----------------------------
  3. -- Table structure for neumaticos_historial
  4. -- ----------------------------
  5. DROP TABLE IF EXISTS `neumaticos_historial`;
  6. CREATE TABLE `neumaticos_historial` (
  7.   `id_interno` int(11) unsigned NOT NULL AUTO_INCREMENT,
  8.   `id_vehiculo` int(11) unsigned NOT NULL,
  9.   `kms_vehiculo` int(11) NOT NULL,
  10.   `fecha` date NOT NULL,
  11.   `posicion` smallint(6) NOT NULL,
  12.   `id_neumatico` int(11) unsigned NOT NULL,
  13.   `prof_ext` decimal(3,1) NOT NULL,
  14.   `prof_med` decimal(3,1) NOT NULL,
  15.   `prof_int` decimal(3,1) NOT NULL,
  16.   `movimiento` varchar(30) COLLATE utf8_spanish_ci NOT NULL,
  17.   PRIMARY KEY (`id_interno`),
  18.   UNIQUE KEY `id_interno_idx` (`id_interno`),
  19.   KEY `id_vehiculo_idx` (`id_vehiculo`),
  20.   KEY `id_neumatico_idx` (`id_neumatico`),
  21.   CONSTRAINT `neumaticos_historial_ibfk_1` FOREIGN KEY (`id_neumatico`) REFERENCES `neumaticos_inventario` (`id_interno`) ON UPDATE CASCADE,
  22.   CONSTRAINT `neumaticos_historial_ibfk_2` FOREIGN KEY (`id_vehiculo`) REFERENCES `vehiculos` (`id_interno`) ON UPDATE CASCADE
  23. ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
  24.  
  25. -- ----------------------------
  26. -- Records
  27. -- ----------------------------
  28. INSERT INTO `neumaticos_historial` VALUES ('1', '13', '10000', '2011-01-01', '1', '1', '15.0', '15.0', '15.0', 'cambio_entrante');
  29. INSERT INTO `neumaticos_historial` VALUES ('2', '13', '20000', '2011-02-01', '1', '1', '14.0', '14.0', '14.0', 'cambio_saliente');
  30. INSERT INTO `neumaticos_historial` VALUES ('3', '10', '40000', '2011-03-01', '3', '1', '14.0', '14.0', '14.0', 'cambio_entrante');
  31. INSERT INTO `neumaticos_historial` VALUES ('4', '10', '70000', '2011-04-01', '3', '1', '10.0', '10.0', '10.0', 'cambio_saliente');
  32. INSERT INTO `neumaticos_historial` VALUES ('5', '95', '50000', '2011-05-01', '1', '1', '10.0', '10.0', '10.0', 'cambio_entrante');
  33. INSERT INTO `neumaticos_historial` VALUES ('6', '13', '12000', '2011-01-10', '2', '2', '15.0', '15.0', '15.0', 'cambio_entrante');
  34. INSERT INTO `neumaticos_historial` VALUES ('7', '13', '20000', '2011-02-01', '2', '2', '14.0', '14.0', '14.0', 'cambio_saliente');
  35. INSERT INTO `neumaticos_historial` VALUES ('8', '12', '40000', '2011-03-11', '4', '2', '14.0', '14.0', '13.0', 'cambio_entrante');
  36. INSERT INTO `neumaticos_historial` VALUES ('9', '12', '50000', '2011-04-11', '4', '2', '11.0', '11.0', '12.0', 'cambio_saliente');
  37. INSERT INTO `neumaticos_historial` VALUES ('10', '95', '50000', '2011-05-01', '2', '2', '11.0', '11.0', '12.0', 'cambio_entrante');
  38. INSERT INTO `neumaticos_historial` VALUES ('11', '13', '10000', '2011-01-01', '3', '3', '15.0', '15.0', '15.0', 'cambio_entrante');
  39. INSERT INTO `neumaticos_historial` VALUES ('12', '13', '20000', '2011-02-01', '3', '3', '14.0', '14.0', '14.0', 'cambio_saliente');
  40. INSERT INTO `neumaticos_historial` VALUES ('13', '95', '50000', '2011-05-01', '3', '3', '14.0', '14.0', '14.0', 'cambio_entrante');
  41. INSERT INTO `neumaticos_historial` VALUES ('14', '13', '10000', '2011-01-01', '4', '4', '15.0', '15.0', '15.0', 'cambio_entrante');
  42. INSERT INTO `neumaticos_historial` VALUES ('15', '13', '20000', '2011-02-01', '4', '4', '13.0', '13.0', '13.0', 'cambio_saliente');
  43. INSERT INTO `neumaticos_historial` VALUES ('16', '95', '50000', '2011-05-01', '4', '4', '13.0', '13.0', '13.0', 'cambio_entrante');
  44. INSERT INTO `neumaticos_historial` VALUES ('17', '95', '50000', '2011-05-01', '4', '4', '15.0', '15.0', '15.0', 'cambio_entrante');
  45. INSERT INTO `neumaticos_historial` VALUES ('18', '95', '50000', '2011-05-01', '5', '5', '15.0', '15.0', '15.0', 'cambio_entrante');
  46. INSERT INTO `neumaticos_historial` VALUES ('19', '95', '50000', '2011-05-01', '6', '6', '15.0', '15.0', '15.0', 'cambio_entrante');
__________________
C[^L*]D
[email protected]
tokkaido.blogspot.com
No hay mejor forma de aprender que enseñar