Advertisement
evilbloodydemon

Untitled

Mar 6th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.43 KB | None | 0 0
  1. WITH popular_movies (movie_id, torrent_count) AS (
  2.     SELECT
  3.         movie_id,
  4.         "count" (*)
  5.     FROM
  6.         torrents
  7.     WHERE
  8.         movie_id IS NOT NULL
  9.     GROUP BY
  10.         movie_id
  11.     ORDER BY
  12.         "count" (*) DESC
  13.     LIMIT 10
  14. )
  15. SELECT
  16.     top_size.title, top_size.SIZE, top_size.info_hash
  17. FROM
  18.     popular_movies pm
  19. JOIN LATERAL (
  20.     SELECT
  21.         *
  22.     FROM
  23.         torrents tt
  24.     WHERE
  25.         tt.movie_id = pm.movie_id
  26.     ORDER BY
  27.         tt. SIZE DESC
  28.     LIMIT 10
  29. ) top_size ON (TRUE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement