Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. SELECT userjokeid, joketypeid, rating, addct, sendct,viewct
  2. FROM
  3. (
  4. SELECT DISTINCT ON(originaljokeid) ujs.userjokeid, j.joketypeid,
  5. CASE
  6. WHEN MAX(ujs.uniqueviewcount) > 0
  7. THEN ((MAX(ujs.addtojokeboxcount)::float8 + MAX(ujs.sendtofriendcount)::float8) * 10000 / MAX(ujs.uniqueviewcount)::float8)
  8. ELSE 0
  9. END as rating
  10. , MAX(ujs.addtojokeboxcount) as addct
  11. , MAX(ujs.sendtofriendcount) as sendct
  12. , MAX(ujs.uniqueviewcount) as viewct
  13. FROM jokebox.userjokestats ujs
  14. INNER JOIN jokebox.userjoke uj
  15. ON ujs.userjokeid = uj.userjokeid
  16. INNER JOIN jokebox.jokes j ON j.jokeid = uj.jokeid
  17. INNER JOIN jokebox.jokestats js ON uj.jokeid = js.jokeid
  18. WHERE js.circulationlevelid = 1
  19. AND uj.jokestatusid = 2
  20. AND js.copyrighted = false
  21. AND j.joketypeid = 3
  22. GROUP BY originaljokeid, ujs.userjokeid, j.joketypeid
  23. ORDER BY originaljokeid, rating DESC
  24. ) AS foo
  25. where viewct > 9
  26. ORDER BY rating desc
  27. LIMIT 96
Add Comment
Please, Sign In to add comment