Guest User

Untitled

a guest
Jun 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. SELECT user_id,
  2. SUM(COALESCE(point_points, 0)) AS total_points,
  3. SUM(
  4. CASE
  5. WHEN point_date > '$this_month'
  6. THEN point_points
  7. ELSE 0
  8. END) AS month_points,
  9. COUNT(DISTINCT c_id) AS num_comments,
  10. COUNT(DISTINCT rant_id) AS live_submissions
  11. FROM users
  12. LEFT JOIN points
  13. ON users.user_id = points.point_userid
  14. LEFT JOIN comments
  15. ON
  16. (
  17. c_userid = user_id
  18. )
  19. LEFT JOIN rants
  20. ON
  21. (
  22. rant_poster = user_id
  23. AND rant_status = 1
  24. )
  25. WHERE user_id = $id
  26. GROUP BY user_id
  27.  
  28. SELECT u.user_id, SUM(COALESCE(p.point_points, 0)) AS total_points,
  29. SUM( CASE WHEN p.point_date > '$this_month' THEN p.point_points ELSE 0 END ) AS month_points
  30. FROM users u LEFT JOIN points p
  31. ON u.user_id = p.point_userid
  32. WHERE u.user_id = $id
  33. GROUP BY u.user_id;
  34.  
  35. SELECT user_id, COUNT(c.c_id) as num_comments,
  36. FROM users u LEFT JOIN comments c
  37. ON (c.c_userid = u.user_id)
  38. WHERE u.user_id = $id
  39. GROUP BY u.user_id;
  40.  
  41. SELECT u.user_id, COUNT(r.rant_id) as live_submissions
  42. FROM users u LEFT JOIN rants r
  43. ON (r.rant_poster = u.user_id AND r.rant_status = 1)
  44. WHERE u.user_id = $id
  45. GROUP BY u.user_id;
  46.  
  47. SELECT UserId, C.num_comments, P.total_points
  48. FROM users
  49. LEFT JOIN
  50. (SELECT c_userId, COUNT(DISTINCT c_id) as num_comments
  51. FROM Comments
  52. GROUP BY c_userId)
  53. AS C
  54. ON UserId = c_userid
  55. LEFT JOIN
  56. (SELECT point_userId, sum(COALESCE(point_points, 0)) as total_points
  57. FROM Points
  58. GROUP BY point_userId)
  59. AS P
  60. ON UserId = point_userid
Add Comment
Please, Sign In to add comment