-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_multilevel_db.sql
38 lines (30 loc) · 1.59 KB
/
create_multilevel_db.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* glasnost_daily */
DROP TABLE IF EXISTS `glasnost_daily`;
CREATE TABLE IF NOT EXISTS `glasnost_daily` (
`counter` int NOT NULL,
`rangedate` datetime NOT NULL,
`destination` varchar(128) NOT NULL,
`country_code` varchar(128) NOT NULL,
PRIMARY KEY (rangedate, destination, country_code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
INSERT INTO glasnost_daily SELECT COUNT(*) as counter, DATE(date) as rangedate, destination, country_code FROM glasnost GROUP BY destination, country_code, DATE(rangedate);
/* glasnost_monthly */
DROP TABLE IF EXISTS `glasnost_monthly`;
CREATE TABLE IF NOT EXISTS `glasnost_monthly` (
`counter` int NOT NULL,
`rangedate` datetime NOT NULL,
`destination` varchar(128) NOT NULL,
`country_code` varchar(128) NOT NULL,
PRIMARY KEY (rangedate, destination, country_code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
INSERT INTO glasnost_monthly SELECT COUNT(*) as counter, LAST_DAY(date) as rangedate, destination, country_code FROM glasnost GROUP BY destination, country_code, LAST_DAY(rangedate);
/* glasnost_yearly */
DROP TABLE IF EXISTS `glasnost_yearly`;
CREATE TABLE IF NOT EXISTS `glasnost_yearly` (
`counter` int NOT NULL,
`rangedate` datetime NOT NULL,
`destination` varchar(128) NOT NULL,
`country_code` varchar(128) NOT NULL,
PRIMARY KEY (rangedate, destination, country_code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
INSERT INTO glasnost_yearly SELECT COUNT(*) as counter, MAKEDATE(YEAR(date), 1) as rangedate, destination, country_code FROM glasnost GROUP BY destination, country_code, MAKEDATE(YEAR(rangedate), 1);