Am trying to write a query to display all the vehicles fuel consumption per month from January to December depending with the year picked by a user. the objective is to get something like this.
+-------------+---------------------------------------------------------+
| Vehicle | Jan | Feb | Mar | Arp | May | Jun | Jul | Aug | Sep |...|
+-------------+---------------------------------------------------------+
| NY001 | 30 | 44 | 54 | 98 | 12 | 37 | 76 | | 32 |...|
| NY002 | 30 | 65 | 99 | | 12 | 85 | | 13 | 52 |...|
| NY003 | 30 | 95 | 24 | 98 | | 55 | 76 | 43 | |...|
| NY004 | | 22 | 97 | | 12 | 28 | | | 12 |...|
| NY005 | 30 | 36 | 15 | 98 | 12 | 65 | 36 | 23 | 66 |...|
| NY006 | | 76 | 34 | 98 | 12 | 75 | 16 | 93 | 97 |...|
+-------------+---------------------------------------------------------+
My table syntax is like below
CREATE TABLE `COSTING` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`Vehicle` varchar(100) NOT NULL DEFAULT '',
`Fueldate` datetime NOT NULL,
`Costcenter` varchar(200) NOT NULL DEFAULT '',
`Code` varchar(100) NOT NULL DEFAULT '',
`Cost` int(100) NOT NULL DEFAULT '0',
`FuelLitters` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=latin1;
How do i do this using mysql query. Please help me. am new in this.
Sample data:
Vehicle | Fueldate | Cost | FuelLitters
----------------------------------------
s213 2016-11-10 17536 96.87
S055 2016-11-23 350 12.66
s213 2016-11-15 7204 33.87
s213 2016-11-24 10827 34.66
S530 2016-11-29 4063 42.81
s515 2016-11-26 20599 250
S513 2016-11-26 9108 110.94
S213 2016-12-29 4400 46.36
S212 2016-11-29 6708 70.68
S211 2016-12-29 3059 32.23
S210 2016-11-28 3950 41.62
S513 2016-12-29 2428 25.58
s160 2016-11-25 4002 42.17
MGT02T 2016-11-26 20804 219.21