Advertisement
semivori

Untitled

May 12th, 2021
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.82 KB | None | 0 0
  1.             SELECT t2.entity_id AS player_id, t2.sum, (t2.sum + t3.avg) / (IF(t2.count > 5, 5, t2.count) + 1) AS points_value FROM (
  2.                     SELECT entity_id FROM points_history LEFT JOIN players ON players.id = points_history.entity_id WHERE players.is_active = 1 GROUP BY entity_id
  3.             ) AS t1,
  4.             LATERAL (
  5.                 SELECT entity_id, SUM(points) AS sum, COUNT(entity_id) AS count FROM (
  6.                     SELECT entity_id, points FROM points_history WHERE t1.entity_id = points_history.entity_id AND points_history.season_id=2 ORDER BY id DESC LIMIT 5
  7.                 ) AS t4
  8.             ) AS t2,
  9.             LATERAL (
  10.                 SELECT IFNULL(AVG(points), 0) AS avg FROM points_history WHERE t1.entity_id = points_history.entity_id AND points_history.season_id=2
  11.             ) AS t3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement