Guest User

Untitled

a guest
Jun 25th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. $standing =DB::select("SELECT DISTINCT
  2. users.id,
  3. username,
  4. SUM(points) AS pts,
  5. count(users_games.user_id) AS CountGame,
  6. (SELECT count(user_id) FROM users_games WHERE points=3 AND user_id=users.id ) AS win,
  7. (SELECT count(user_id) FROM users_games WHERE points=0 AND user_id=users.id ) AS los,
  8. (SELECT count(user_id) FROM users_games WHERE points=1 AND user_id=users.id ) AS draw
  9. FROM users_games,users
  10. WHERE users_games.user_id=users.id
  11. AND score_home IS NOT NULL
  12. AND score_away IS NOT NULL
  13. AND points IS NOT NULL
  14. GROUP BY users.id
  15. ORDER BY pts DESC,win DESC,draw DESC,CountGame DESC");
  16.  
  17. $query= DB::table('users_games')
  18. ->join('users','users.id','=','users_games.user_id')
  19. ->where('users_games.user_id','=','users.id')
  20. ->whereNotNull('users_games.score_home')
  21. ->whereNotNull('users_games.score_away')
  22. ->whereNotNull('users_games.points')
  23. ->groupBy('users.id')
  24. ->orderBy('pts','desc')
  25. ->orderBy('win','desc')
  26. ->orderBy('draw','desc')
  27. ->orderBy('CountGame','desc')
  28. ->select('users.id','sum(points) as pts','count(users_games.user_id) as CountGame','(select count(user_id) from user_games where points=3 and user_id=users.id) as win','(select count(user_id) from user_games where points=0 and user_id=users.id) as los','(select count(user_id) from user_games where points=1 and user_id=users.id) as draw')
  29. ->get();
  30.  
  31. $query= DB::table('users_games')
  32. ->join('users','users.id','=','users_games.user_id')
  33. ->select('users.id',
  34. 'username',
  35. DB::raw('SUM(points) as pts'),
  36. DB::raw('count(users_games.user_id) as CountGame'),
  37. DB::raw('(select count(user_id) from users_games where points=3 and user_id=users.id) as win'),
  38. DB::raw('(select count(user_id) from users_games where points=0 and user_id=users.id) as los'),
  39. DB::raw('(select count(user_id) from users_games where points=1 and user_id=users.id) as draw'))
  40. ->whereNotNull('users_games.score_home')
  41. ->whereNotNull('users_games.score_away')
  42. ->whereNotNull('users_games.points')
  43. ->orderBy('pts','desc')
  44. ->orderBy('win','desc')
  45. ->orderBy('draw','desc')
  46. ->orderBy('CountGame','desc')
  47. ->groupBy('users.id')
  48. ->get();
Add Comment
Please, Sign In to add comment