Can anyone help me understand this SQL query in PostgreSQL ?
SELECT sum(count)
FROM (
SELECT count,
time,
max(time) OVER (PARTITION BY post_id) max_time
FROM totals
WHERE cust_id IN %s
AND time < %s
AND type = %s
) as ss
WHERE time = max_time;
Additional comment
To explain my comments on the OP I was having with a_horse_with_no_name, this query could be re-written as follows:
I believe this makes it clearer what this query is doing (since it a more standard form.)
Original Comment
Let me make a guess — lets say count is the number of views and time is the time that there are those views. My guess is it is something like this. But KM won’t tell us.
In any case if that is how it works then this is what the query does:
It gives the total views of all posts.
(As limited by the incoming parameters)
I could explain why, but I’ll wait for you to apologize for cursing at me.