Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DROP TABLE IF EXISTS `cuti`;
- CREATE TABLE IF NOT EXISTS `cuti` (
- `nama` varchar(11) NOT NULL,
- `tgl1` date NOT NULL,
- `tgl2` date NOT NULL
- ) ENGINE=MyISAM;
- INSERT INTO `cuti` (`nama`, `tgl1`, `tgl2`) VALUES
- ('bejo', '2016-06-29', '2016-07-03'),
- ('agus', '2016-07-03', '2016-07-07'),
- ('surti', '2016-07-01', '2016-07-05');
- SELECT
- COUNT(a.nama) AS jml,
- DATE_ADD(a1.t1,INTERVAL td.digit DAY) AS tgl
- FROM
- (
- SELECT (b1.d+b2.d+b4.d+b8.d+b16.d) AS digit
- FROM
- (SELECT 0 d UNION ALL SELECT 1 d ) b1
- CROSS JOIN (SELECT 0 d UNION ALL SELECT 2 d ) b2
- CROSS JOIN (SELECT 0 d UNION ALL SELECT 4 d ) b4
- CROSS JOIN (SELECT 0 d UNION ALL SELECT 8 d ) b8
- CROSS JOIN (SELECT 0 d UNION ALL SELECT 16 d ) b16
- ) td,
- (
- SELECT MIN( tgl1 ) t1, MAX( tgl2 ) t2
- FROM cuti
- ) a1,
- cuti a
- WHERE
- a.tgl1<=DATE_ADD(a1.t1,INTERVAL td.digit DAY)
- AND a.tgl2>=DATE_ADD(a1.t1,INTERVAL td.digit DAY)
- GROUP BY
- DATE_ADD(a1.t1,INTERVAL td.digit DAY) ;
- +-----+------------+
- | jml | tgl |
- +-----+------------+
- | 1 | 2016-06-29 |
- | 1 | 2016-06-30 |
- | 2 | 2016-07-01 |
- | 2 | 2016-07-02 |
- | 3 | 2016-07-03 |
- | 2 | 2016-07-04 |
- | 2 | 2016-07-05 |
- | 1 | 2016-07-06 |
- | 1 | 2016-07-07 |
- +-----+------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement