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 39 40 41 42 43 44 45 46 47 48
| CREATE TEMPORARY TABLE `album_statistics` (
`id` int(11) NOT NULL auto_increment,
`album_id` int(11) NOT NULL,
`week_fan_count` int(11) NOT NULL DEFAULT '0',
`week_critic_count` int(11) NOT NULL DEFAULT '0',
`week_read_count` int(11) NOT NULL DEFAULT '0',
`week_global_avg` decimal(10,5) DEFAULT null,
`week_illustration_avg` decimal(10,5) DEFAULT null,
`week_scenario_avg` decimal(10,5) DEFAULT null,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
insert into `album_statistics` (album_id)
select `albums`.`id` from `albums` where `albums`.`displayed` = 1 and `albums`.`deleted` = 0;
update `album_statistics`
set `album_statistics`.`week_fan_count` = (
select count(*) from `favorite_albums`
where (DATEDIFF(CURDATE(), `favorite_albums`.`created_on`) < 7) and `favorite_albums`.`album_id` = `album_statistics`.`album_id`
);
update `album_statistics`
set `album_statistics`.`week_read_count` = (
select count(*) from `album_views`
where (DATEDIFF(CURDATE(), `album_views`.`date`) < 7) and `album_views`.`album_id` = `album_statistics`.`album_id`
and `album_views`.`read` = 1
);
update `album_statistics` as a
left outer join (
select c.`album_id`, count(*) as total, avg(c.`global_rating`) as global_rating, avg(c.`scenario_rating`) as scenario_rating, avg(c.`illustration_rating`) as illustration_rating
from `critics` as c
inner join `albums` on `albums`.`id` = c.`album_id`
where DATEDIFF(CURDATE(), c.`created_on`) < 7 and `albums`.`deleted` = 0 and `albums`.`displayed` = 1
group by c.`album_id`
) as ca on a.`album_id` = ca.`album_id`
set a.`week_critic_count` = ifnull(ca.total, 0),
a.`week_global_avg` = ifnull(ca.global_rating, 0),
a.`week_scenario_avg` = ifnull(ca.scenario_rating, 0),
a.`week_illustration_avg` = ifnull(ca.illustration_rating, 0);
update `albums`
inner join `album_statistics` on `albums`.`id` = `album_statistics`.`album_id`
set `albums`.`week_popularity` = (
calcul de la popularité
)
where `albums`.`id` = `album_statistics`.`album_id`
; |
Partager