I do not know English, sorry :(
example table:
CREATE TABLE IF NOT EXISTS `__example__` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`amount` decimal(10,2) DEFAULT NULL,
`fromDate` datetime DEFAULT NULL,
`toDate` datetime DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
and rows:
INSERT INTO `__example__` (`ID`, `amount`, `fromDate`, `toDate`)
VALUES (1, 1000.00, '2016-01-16 17:05:40', '2016-01-26 17:05:45');
INSERT INTO `__example__` (`ID`, `amount`, `fromDate`, `toDate`)
VALUES (2, 1000.00, '2016-01-26 17:05:40', '2016-02-05 17:05:45');
INSERT INTO `__example__` (`ID`, `amount`, `fromDate`, `toDate`)
VALUES (3, 1000.00, '2015-12-26 17:05:40', '2016-01-05 17:05:45');
INSERT INTO `__example__` (`ID`, `amount`, `fromDate`, `toDate`)
VALUES (4, 4000.00, '2015-12-26 17:05:40', '2016-02-04 17:05:45');
I want to see:
year | month | sum
2015 | 12 | 1400.00
2016 | 01 | 4700.00
2016 | 02 | 900.00
Example:
2 rows started at 12/2015 and the sum thereof is 5000.00(1000+4000).
But 12/2015 sum column should be 1400.00.
How can I do that with SQL query? Help me, please.