Advertisement
beowulf1416

users per country top 3

Mar 3rd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. select
  2. res.*,
  3. res.current_week + res.last_week_days total_users
  4. from
  5. (
  6. select
  7. country.title country_title,
  8. 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,
  9. 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
  10. from report_2015_1 report
  11. inner join data_gateway dg on report.gateway_id = dg.id
  12. inner join data_group_country country on dg.country_id = country.id
  13. where dg.title is not null
  14. and dg.is_deleted = 0
  15. and country.is_deleted = 0
  16. and country.title is not null
  17. and date(report.report_date) >= '2015-02-14'
  18. and date(report.report_date) <= '2015-02-27'
  19. group by country.id
  20. ) res
  21. order by total_users desc, country_title asc
  22. limit 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement