1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| --------------
START TRANSACTION
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `test`
--------------
--------------
CREATE TABLE `test`
( `exe_id` smallint unsigned NOT NULL,
`type_id` char(03) NOT NULL,
`val_id` smallint unsigned NOT NULL,
`prod_id` tinyint unsigned NOT NULL,
`mag_id` tinyint unsigned NOT NULL,
`qte` integer unsigned NOT NULL,
`unite` char(04) NOT NULL,
`stock_date` datetime NOT NULL,
PRIMARY KEY (`exe_id`,`type_id`,`val_id`)
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `test` (`exe_id`,`type_id`,`val_id`,`prod_id`,`mag_id`,`qte`,`unite`,`stock_date`) VALUES
(2019, 'HAR', 16, 1, 1, 600, 'cndt', '2019-02-19 16:46:42'),
(2019, 'HAR', 35, 1, 1, 595, 'cndt', '2019-02-19 17:41:14'),
(2019, 'HAR', 38, 1, 1, 581, 'cndt', '2019-02-20 16:13:42'),
(2019, 'HAR', 41, 1, 1, 531, 'cndt', '2019-02-20 16:15:51'),
(2019, 'HAR', 44, 1, 1, 486, 'cndt', '2019-02-20 16:46:35')
--------------
--------------
select * from `test`
--------------
+--------+---------+--------+---------+--------+-----+-------+---------------------+
| exe_id | type_id | val_id | prod_id | mag_id | qte | unite | stock_date |
+--------+---------+--------+---------+--------+-----+-------+---------------------+
| 2019 | HAR | 16 | 1 | 1 | 600 | cndt | 2019-02-19 16:46:42 |
| 2019 | HAR | 35 | 1 | 1 | 595 | cndt | 2019-02-19 17:41:14 |
| 2019 | HAR | 38 | 1 | 1 | 581 | cndt | 2019-02-20 16:13:42 |
| 2019 | HAR | 41 | 1 | 1 | 531 | cndt | 2019-02-20 16:15:51 |
| 2019 | HAR | 44 | 1 | 1 | 486 | cndt | 2019-02-20 16:46:35 |
+--------+---------+--------+---------+--------+-----+-------+---------------------+
--------------
select t1.*
from `test` as t1
left outer join `test` as t2
on t2.stock_date > t1.stock_date
and t2.stock_date < '2019-02-20 16:15:00'
and t2.exe_id = 2019
and t2.prod_id = 1
and t2.mag_id = 1
where t1.stock_date < '2019-02-20 16:15:00'
and t1.exe_id = 2019
and t1.prod_id = 1
and t1.mag_id = 1
and t2.exe_id is null
--------------
+--------+---------+--------+---------+--------+-----+-------+---------------------+
| exe_id | type_id | val_id | prod_id | mag_id | qte | unite | stock_date |
+--------+---------+--------+---------+--------+-----+-------+---------------------+
| 2019 | HAR | 38 | 1 | 1 | 581 | cndt | 2019-02-20 16:13:42 |
+--------+---------+--------+---------+--------+-----+-------+---------------------+
--------------
COMMIT
--------------
Appuyez sur une touche pour continuer... |
Partager