beowulf1416

Untitled

Aug 14th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. set @row = 1;
  2. set @group = '';
  3. set @row_country = 0;
  4.  
  5. select
  6. b.content_id,
  7. b.content_title,
  8. b.country_id,
  9. b.date,
  10. round(b.sum_seconds/60) total_minutes
  11. from
  12. (
  13. select
  14. a.*,
  15. @row := if(@group = a.country_id, @row + 1, 1) row_num,
  16. @group := a.country_id dummy
  17. from
  18. (
  19. select
  20. sl.date,
  21. sl.content_id,
  22. dc.title content_title,
  23. dc.country_id,
  24. sum(sl.seconds) sum_seconds
  25. from summary_listen sl
  26. inner join data_content dc on dc.id = sl.content_id
  27. where dc.is_deleted = 0
  28. and dc.country_id in (
  29. select
  30. d.country_id
  31. from
  32. (
  33. select
  34. c.*,
  35. @row_country := @row_country + 1 row_country
  36. from
  37. (
  38. select
  39. dc_1.country_id,
  40. sum(sl_1.seconds) sum_seconds_country
  41. from summary_listen sl_1
  42. inner join data_content dc_1 on dc_1.id = sl_1.content_id
  43. where dc_1.is_deleted = 0
  44. and date(sl_1.date) = '2015-08-03'
  45. group by dc_1.country_id
  46. order by sum_seconds_country desc
  47. ) c
  48. ) d
  49. where d.row_country < 21
  50. )
  51. and date(sl.date) = '2015-08-03'
  52. group by sl.date, sl.content_id
  53. order by dc.country_id, sum_seconds desc
  54. ) a
  55. ) b
  56. where b.row_num < 6
  57. order by b.country_id, total_minutes desc
Advertisement
Add Comment
Please, Sign In to add comment