Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 (
- 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
- ) AS t1,
- LATERAL (
- SELECT entity_id, SUM(points) AS sum, COUNT(entity_id) AS count FROM (
- 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
- ) AS t4
- ) AS t2,
- LATERAL (
- SELECT IFNULL(AVG(points), 0) AS avg FROM points_history WHERE t1.entity_id = points_history.entity_id AND points_history.season_id=2
- ) AS t3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement