From 26cd95cab8f448bd33e1fe677d9dadc377d1491f Mon Sep 17 00:00:00 2001 From: Risto Lahtela Date: Fri, 1 Feb 2019 14:27:18 +0200 Subject: [PATCH] Fix networkGeolocationCounts for MySQL --- .../db/access/queries/ServerAggregateQueries.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/ServerAggregateQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/ServerAggregateQueries.java index 631c9da88..ec5f55a9d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/ServerAggregateQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/ServerAggregateQueries.java @@ -182,14 +182,19 @@ public class ServerAggregateQueries { } public static Query> networkGeolocationCounts() { - String subQuery = "SELECT " + - GeoInfoTable.USER_UUID + ", " + + String subQuery1 = "SELECT " + + GeoInfoTable.ID + ", " + GeoInfoTable.GEOLOCATION + ", " + GeoInfoTable.LAST_USED + ", " + + " FROM " + GeoInfoTable.TABLE_NAME; + String subQuery2 = "SELECT " + + GeoInfoTable.ID + ", " + "MAX(" + GeoInfoTable.LAST_USED + ") as m" + " FROM " + GeoInfoTable.TABLE_NAME + " GROUP BY " + GeoInfoTable.USER_UUID; - String sql = "SELECT " + GeoInfoTable.GEOLOCATION + ", COUNT(1) as c FROM (" + subQuery + ") AS q1" + + String sql = "SELECT " + GeoInfoTable.GEOLOCATION + ", COUNT(1) as c FROM (" + + "(" + subQuery1 + ") AS q1" + + " INNER JOIN (" + subQuery2 + ") AS q2 ON q1.id = q2.id)" + " WHERE " + GeoInfoTable.LAST_USED + " = m" + " GROUP BY " + GeoInfoTable.GEOLOCATION;