Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @row = 1;
- set @group = '';
- set @row_country = 0;
- select
- b.content_id,
- b.content_title,
- b.country_id,
- b.date,
- round(b.sum_seconds/60) total_minutes
- from
- (
- select
- a.*,
- @row := if(@group = a.country_id, @row + 1, 1) row_num,
- @group := a.country_id dummy
- from
- (
- select
- sl.date,
- sl.content_id,
- dc.title content_title,
- dc.country_id,
- sum(sl.seconds) sum_seconds
- from summary_listen sl
- inner join data_content dc on dc.id = sl.content_id
- where dc.is_deleted = 0
- and dc.country_id in (
- select
- d.country_id
- from
- (
- select
- c.*,
- @row_country := @row_country + 1 row_country
- from
- (
- select
- dc_1.country_id,
- sum(sl_1.seconds) sum_seconds_country
- from summary_listen sl_1
- inner join data_content dc_1 on dc_1.id = sl_1.content_id
- where dc_1.is_deleted = 0
- and date(sl_1.date) = '2015-08-03'
- group by dc_1.country_id
- order by sum_seconds_country desc
- ) c
- ) d
- where d.row_country < 21
- )
- and date(sl.date) = '2015-08-03'
- group by sl.date, sl.content_id
- order by dc.country_id, sum_seconds desc
- ) a
- ) b
- where b.row_num < 6
- order by b.country_id, total_minutes desc
Advertisement
Add Comment
Please, Sign In to add comment