From d18b4c4a5f7f8a2d1505bd03c91a3c2c989dadad Mon Sep 17 00:00:00 2001
From: schneefux <schneefux+commit@schneefux.xyz>
Date: Tue, 14 Mar 2017 20:48:43 +0100
Subject: fix participant_stats query

---
 queries/participant/stats.sql | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

(limited to 'queries/participant/stats.sql')

diff --git a/queries/participant/stats.sql b/queries/participant/stats.sql
index 05a9697..6a6d540 100644
--- a/queries/participant/stats.sql
+++ b/queries/participant/stats.sql
@@ -1,13 +1,17 @@
 WITH stats AS (
     SELECT
-        api_id,
+        participant.api_id,
+        match.patch_version,
         CASE WHEN roster.hero_kills=0
         THEN 0
         ELSE (kills+assists)/roster.hero_kills::float
-        END AS kill_participation
-    FROM participant JOIN roster ON roster.api_id=participant.roster_api_id
+        END AS kills_participation
+    FROM participant
+    JOIN roster ON roster.api_id=participant.roster_api_id
+    JOIN match ON match.api_id=roster.match_api_id
+    WHERE participant.api_id = $1
 )
-INSERT INTO participant_stats(participant_api_id, kill_participation)
+INSERT INTO participant_stats(participant_api_id, patch_version, kills_participation)
 SELECT * FROM stats
 ON CONFLICT(participant_api_id) DO
-UPDATE SET(participant_api_id, kill_participation) = (SELECT * FROM stats)
+UPDATE SET(participant_api_id, patch_version, kills_participation) = (SELECT * FROM stats)
-- 
cgit v1.3.1

