Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- res.*,
- res.current_week + res.last_week_days total_users
- from
- (
- select
- country.title country_title,
- sum(case when date(report.report_date) >= '2015-02-22' and date(report.report_date) <= '2015-02-27' then report.users_by_time else 0 end) current_week,
- sum(case when date(report.report_date) >= '2015-02-15' and date(report.report_date) <= '2015-02-20' then report.users_by_time else 0 end) last_week_days
- from report_2015_1 report
- inner join data_gateway dg on report.gateway_id = dg.id
- inner join data_group_country country on dg.country_id = country.id
- where dg.title is not null
- and dg.is_deleted = 0
- and country.is_deleted = 0
- and country.title is not null
- and date(report.report_date) >= '2015-02-14'
- and date(report.report_date) <= '2015-02-27'
- group by country.id
- ) res
- order by total_users desc, country_title asc
- limit 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement