I have a query I run in my ti_userevent database that combines users play session lengths from multiple play sessions and instead returns the total play length for each player between a set time and date (Instead of 4 sessions for Player 1, it returns 1 and gives me the total play length of all 4 sessions).
This query allows me to set the date and time range for the data I am looking for in MetaBase, and returns the player ID, player name and total play length across multiple sessions for each user within the timeframe provided.
This is the query.
SELECT t2.playername,
    (EXTRACT(EPOCH
        FROM ( MAX(t.local_time) - MIN(t.local_time)) ::INTERVAL)/60)::integer as duration
            FROM ti_userevent t
        JOIN
    (SELECT DISTINCT t2.value as playerName, t2.session_id
            FROM ti_userevent t2
                WHERE context = 'Player' 
                AND
                action = 'Name'
                    [[AND local_time >= {{StartTime}}::timestamp at time zone 'US/Pacific']]
                    [[AND local_time < {{EndTime}}::timestamp at time zone 'US/Pacific']]
            ) t2
        ON t2.session_id = t.session_id
GROUP BY t2.playername;
Example Data:
   User ID        User Name   Play Length of all sessions
    ID1             Name 1          105
    ID2             Name 2          215
    ID3             Name 3          352
But, I would also like to get their average FPS, GPU and Frame performance from the Query. The problem is, these are all stored in the same table!
In order to get the average GPU performance I run the following, this only gives me the average performance based on the build number.
SELECT
    session_id
    , value::decimal as AvgGpuMs
FROM 
    ti_userevent
WHERE 
        context = 'Perf'
    AND action = 'GpuMs'
    AND session_id IN 
        (SELECT DISTINCT session_id
            FROM 
                ti_userevent
            WHERE 
                action = 'BuildNum'
                and value = {{BuildNum}})
Example Data:
user_id    session_id    avggpums
ID1         session1       8.2
ID2         session1       8.7
ID3         session1       9.7
I have to run the same query above for the AvgFPS and AvgFrameMs performance.
What I would like is to combine the 3 AvgFPS, AvgFrameMs and AvgGPUms queries into the first Play session length query. I would like to have them all run off the timeframe range in the first query... I have tried several times and am having a hard time getting it to return the data I am after.
I am not the best with SQL so I am hoping someone on here could help me. Thanks for all your help!
 
    