ALTER TABLE counter_monthly_log RENAME TO counter_monthly_log_old
CREATE TABLE counter_monthly_log ( year int(11) NOT NULL, month int(11) NOT NULL, journal_id int(11) NOT NULL, count_html int(20) NOT NULL DEFAULT 0, count_pdf int(20) NOT NULL DEFAULT 0, count_other int(20) NOT NULL DEFAULT 0, UNIQUE KEY counter_monthly_log_ukey (year,month,journal_id) )
CREATE TABLE counter_monthly_log ( year INT8 NOT NULL, journal_id INT8 NOT NULL, month INT8 NOT NULL, count_html INT8 DEFAULT 0 NOT NULL, count_pdf INT8 DEFAULT 0 NOT NULL, count_other INT8 DEFAULT 0 NOT NULL)
CREATE UNIQUE INDEX counter_monthly_log_key ON counter_monthly_log (year, month, journal_id)
INSERT INTO counter_monthly_log (year,month,journal_id,count_html,count_pdf,count_other) SELECT year, 1 as month, journal_id, 0, count_jan as count, 0 FROM counter_monthly_log_old UNION SELECT year, 2 as month, journal_id, 0, count_feb as count, 0 FROM counter_monthly_log_old UNION SELECT year, 3 as month, journal_id, 0, count_mar as count, 0 FROM counter_monthly_log_old UNION SELECT year, 4 as month, journal_id, 0, count_apr as count, 0 FROM counter_monthly_log_old UNION SELECT year, 5 as month, journal_id, 0, count_may as count, 0 FROM counter_monthly_log_old UNION SELECT year, 6 as month, journal_id, 0, count_jun as count, 0 FROM counter_monthly_log_old UNION SELECT year, 7 as month, journal_id, 0, count_jul as count, 0 FROM counter_monthly_log_old UNION SELECT year, 8 as month, journal_id, 0, count_aug as count, 0 FROM counter_monthly_log_old UNION SELECT year, 9 as month, journal_id, 0, count_sep as count, 0 FROM counter_monthly_log_old UNION SELECT year, 10 as month, journal_id, 0, count_oct as count, 0 FROM counter_monthly_log_old UNION SELECT year, 11 as month, journal_id, 0, count_nov as count, 0 FROM counter_monthly_log_old UNION SELECT year, 12 as month, journal_id, 0, count_dec as count, 0 FROM counter_monthly_log_old ORDER BY journal_id, year, month
DROP TABLE IF EXISTS counter_monthly_log_old
DROP TABLE counter_monthly_log_old CASCADE