CREATE TABLE `monthly1` (
`id` int(255) NOT NULL,
`year` int(255) NOT NULL,
`stat_id` varchar(255) NOT NULL,
`cat_id` varchar(255) NOT NULL,
`january` varchar(255) NOT NULL,
`february` varchar(255) NOT NULL,
`march` varchar(255) NOT NULL,
`april` varchar(255) NOT NULL,
`may` varchar(255) NOT NULL,
`june` varchar(255) NOT NULL,
`july` varchar(255) NOT NULL,
`august` varchar(255) NOT NULL,
`september` varchar(255) NOT NULL,
`october` varchar(255) NOT NULL,
`november` varchar(255) NOT NULL,
`december` varchar(255) NOT NULL,
);
Hi i have an existing mysql data with structure like above and i would like to migrate the data to a new structure like in the structure below
CREATE TABLE `monthly2` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`year` int(255) NOT NULL,
`stat_id` varchar(255) NOT NULL,
`cat_id` int(11) NOT NULL,
`monthName` varchar(255) NOT NULL,
`monthlydata` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);
how do i properly create the insert query to do this..i tried the query below but how do i set the monthName to be month name (january) instead of january data ?
INSERT INTO `monthly2` (`year`, `stat_id`, `cat_id`, `monthName`, `monthlydata`)
select `year`,`stat_id`,`cat_id`, `january`, `january`
from `monthly1 WHERE year >= '2010' AND year < '2018'